home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 September / Chip_2002-09_cd1.bin / sharewar / slunec / app / httrack.exe / {app} / src_win / WinHTTrack / Shell.cpp < prev    next >
C/C++ Source or Header  |  2002-07-07  |  102KB  |  2,927 lines

  1. // Shell.cpp : Defines the class behaviors for the application.
  2. //
  3.  
  4. // thread windows
  5. #include <process.h>
  6.  
  7. #include "stdafx.h"
  8. #include "Shell.h"
  9. #include "NewProj.h"
  10.  
  11. // Ras
  12. #if USE_RAS 
  13. #include "RasLoad.h"
  14. #endif
  15.  
  16. #include <afxdisp.h>
  17. #include "ras.h"
  18.  
  19. //#include "ShellDoc.h"
  20. //#include "ShellView.h"
  21.  
  22. #ifdef _DEBUG
  23. #define new DEBUG_NEW
  24. #undef THIS_FILE
  25. static char THIS_FILE[] = __FILE__;
  26. #endif
  27.  
  28. // PATCH-->
  29. // PATCH-->
  30. #include "about.h"
  31. #include "infoend.h"
  32.  
  33. // flag de termination
  34. int termine=0;
  35. int termine_requested=0;
  36. int shell_terminated=0;
  37. int soft_term_requested=0;
  38. FILE* fp_debug=NULL;
  39.  
  40. #include "stdafx.h"
  41. #include "Shell.h"
  42. #include "process.h"
  43. //#include "ShellDoc.h"
  44. //#include "ShellView.h"
  45. //#include "essai.h"
  46. //#include "get.h"
  47. //#include "parameter.h"
  48. extern "C" {
  49.   #include "htssystem.h"
  50. }
  51. #include "Wid1.h"
  52. #include "trans.h"
  53. #include "InfoUrl.h"
  54. //#include "option.h"
  55. //#include "filter.h"
  56. //#include "wizard.h"
  57. //
  58. #include "maintab.h"
  59. //
  60. #include "MemRegister.h"
  61.  
  62. // LANG
  63. #include "newlang.h"
  64.  
  65.  
  66. // PATCH-->
  67. //#include "wizard2.h"
  68. //#include "WizLinks.h"
  69.  
  70. #include "inprogress.h"
  71.  
  72. #include "SYS\TIMEB.H"
  73.  
  74. // htswrap_add
  75. extern "C" {
  76.   #include "htswrap.h"
  77. };
  78.  
  79. // --- --- --- --- Options --- --- --- ---
  80.  
  81. #define MAX_LEN_INPROGRESS 32
  82.  
  83. // lancement en multithread du shell ET de gethostbyname
  84. #define SHELL_MULTITHREAD 1
  85. //#define HTS_XGMETHOD 2    // 1: AfxBeginThread 2: _beginthread
  86. // --- --- --- --- Options --- --- --- ---
  87. //int INREDRAW_LOCKED=0;      // refresh graphique en cours
  88. //int INFILLMEM_LOCKED=0;     // refresh mΘmoire en cours
  89. int HTTRACK_result=0;
  90. //
  91. CInfoUrl* _Cinprogress_inst=NULL;
  92.  
  93. extern HICON httrack_icon;
  94.  
  95. /* Main splitter frame */
  96. #include "DialogContainer.h"
  97. #include "splitter.h"
  98. extern CSplitterFrame* this_CSplitterFrame;
  99.  
  100. /* Main WizTab frame */
  101. #include "WizTab.h"
  102. extern CWizTab* this_CWizTab;
  103. /* Argh - pas de domodal dans des autres threads ?!?! */
  104. char WIZ_question[1000];
  105. char WIZ_reponse[1000];
  106.  
  107.  
  108. // Fonctionnement des THREADS:
  109. //
  110. // principal ---> robot & refresh data (thread 1)
  111. //           ---> refresh graphique    (thread 2)
  112. //           GO!> boucle gestion domodal() et boutons
  113. // arrΩt: principal demande l'arrΩt (termine_requested)
  114. //        thread1 active termine et que thread2 ait fini de refresher
  115. //        thread2 se termine
  116. //        thread1 retourne 0 α hts_loop
  117. //        le robot termine
  118. //        le thread1 active termine, termine le formulaire et se termine
  119. //        principal ayant quittΘ le formulaire affiche le message de fin
  120.  
  121.  
  122. // htslib.c
  123. extern "C" void qsec2str(char *st,TStamp t);
  124.  
  125. // construction index gΘnΘral
  126. // void Build_TopIndex();
  127.  
  128. void compute_options() ;
  129. char* connversion(char chaine[10000]);
  130. void lance(void);
  131. int check_continue(char* pathlog);
  132. int inprogress_refresh();
  133. //int inprogress_refresh_scan();
  134. void Write_profile(CString path,int load_path);
  135. void Read_profile(CString path,int load_path);
  136.  
  137.  
  138. // dΘja fait mais bon
  139. #define HTS_WIN 1
  140.  
  141. extern "C" {
  142.   #include "htscore.h"
  143. }
  144.  
  145. CString _HTTRACK_VERSION = HTTRACK_VERSION;
  146.  
  147. char LINE[32768];
  148. char OPTIONurl[32000];
  149. char OPTIONfilelist[HTS_URLMAXSIZE*2];
  150. char OPTIONproxy[500];
  151. char OPTIONport[100];
  152. char OPTIONdepth[20];
  153. char OPTIONextdepth[20];
  154. char OPTIONget[10];
  155. //char OPTIONlevel[10];
  156. char OPTIONwhere[8];
  157. char OPTIONmeth[8];
  158. char OPTIONmaxfile[100];
  159. char OPTIONmax[100];
  160. char OPTIONfrag[100];
  161. char OPTIONconn[100];
  162. char OPTIONtog[10];
  163. char OPTIONcache[8];
  164. char OPTIONrobots[8];
  165. char choixdeb[8];
  166. char build[256];
  167. char filtre[32];
  168. char OPTIONhtmlfirst[8];
  169. char OPTIONindex[8];
  170. char OPTIONindex2[8];
  171. char OPTIONdos[8];
  172. char OPTIONtime[20];
  173. char OPTIONrate[20];
  174. char OPTIONhostquit[20];
  175. char OPTIONuser[256];
  176. char OPTIONfooter[256];
  177. char OPTIONlog[8];
  178. char OPTIONtestall[8];
  179. char OPTIONparseall[8];
  180. char OPTIONlink[8];
  181. char OPTIONpath[1000];
  182. char OPTIONretry[16];
  183. char OPTIONerrpage[8];
  184. char OPTIONexternal[8];
  185. char OPTIONnopurge[8];
  186. char OPTIONhidepwd[8];
  187. char OPTIONhidequery[8];
  188. char OPTIONcookies[8];
  189. char OPTIONchecktype[8];
  190. char OPTIONparsejava[8];
  191. char OPTIONCache2[8];
  192. char OPTIONlogtype[8];
  193. char OPTIONnorecatch[8];
  194. char OPTIONtoler[8];
  195. char OPTIONupdhack[8];
  196. char OPTIONhttp10[8];
  197. //-->
  198. char OPTIONwaittime[32];
  199. char OPTIONmaxtime[32];
  200. char OPTIONmaxrate[32];
  201. char OPTIONmaxconn[32];
  202. char OPTIONmaxlinks[32];
  203. char OPTIONhh[32];
  204. char OPTIONmm[32];
  205. char OPTIONss[32];
  206. //
  207. char buff_filtres[8192];
  208. char buff_MIME[8192];
  209. // RAS
  210. char OPTION_RasString[256];
  211. RASDIALPARAMS OPTION_dial;
  212.  
  213. // Fichier tempo
  214. FILE* tmpf=NULL;
  215. MemRegister tmpm;
  216.  
  217. CNewProj* dialog0=NULL;
  218. Wid1* dialog1=NULL;
  219. Ctrans* dialog2=NULL;
  220. //Coption dialog3;
  221. //Cfilter diafiltre;
  222. /*
  223. wizard diawiz;
  224. wizard2 diawiz2;
  225. WizLinks diawiz3;
  226. */
  227. //
  228. CMainTab* maintab=NULL;
  229. CShellApp* CShellApp_app=NULL;
  230.  
  231. #include "infoend.h"
  232. extern Cinfoend* this_Cinfoend;
  233.  
  234.  
  235. // PATCH-->
  236. Cinprogress* inprogress=NULL;
  237.  
  238. // nbre de slides
  239. t_StatsBuffer StatsBuffer[NStatsBuffer];
  240. void* StatsBufferback=NULL;
  241. int StatsBufferback_max=0;
  242. InpInfo SInfo;
  243.  
  244. #if USE_RAS
  245. // Chargement des librairies RAS
  246. CDynamicRAS* LibRas=NULL;
  247. int LibRasUse=0;
  248. //
  249. int connected=0;
  250. int disconnect=0;
  251. HRASCONN conn = NULL;
  252. int has_started=0;
  253. char connected_err[1000]="";
  254. #endif
  255.  
  256. // pour message final
  257. extern char end_mirror_msg[8192];
  258. #include "winhttrack.h"
  259. extern CWinHTTrackApp* this_app;
  260.  
  261.  
  262. // PATCH-->
  263. // PATCH-->
  264. // FIN PATCH
  265.  
  266.  
  267. /////////////////////////////////////////////////////////////////////////////
  268. // CShellApp
  269.  
  270. /*
  271. BEGIN_MESSAGE_MAP(CShellApp, CWinApp)
  272. //{{AFX_MSG_MAP(CShellApp)
  273. ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  274. // NOTE - the ClassWizard will add and remove mapping macros here.
  275. //    DO NOT EDIT what you see in these blocks of generated code!
  276. //}}AFX_MSG_MAP
  277. // Standard file based document commands
  278. ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  279. ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  280. // Standard print setup command
  281. ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  282. ON_COMMAND(ID_HELP, CWinApp::OnHelp)
  283. END_MESSAGE_MAP()
  284. */
  285.  
  286. /////////////////////////////////////////////////////////////////////////////
  287. // CShellApp construction
  288.  
  289. CShellApp::CShellApp()
  290. {
  291.   // TODO: add construction code here,
  292.   // Place all significant initialization in InitInstance
  293. }
  294.  
  295. /////////////////////////////////////////////////////////////////////////////
  296. // The one and only CShellApp object
  297.  
  298. //CShellApp theApp;
  299.  
  300. /////////////////////////////////////////////////////////////////////////////
  301. // CShellApp initialization
  302.  
  303. UINT RunBackMirror( LPVOID pP ) {
  304.   CShellApp_app->init_lance();
  305.   return 0;
  306. }
  307.  
  308. BOOL LaunchMirror() {
  309.   WHTT_LOCK();
  310.   hts_resetvar();
  311.   WHTT_UNLOCK();
  312.   AfxBeginThread(RunBackMirror,NULL);
  313.   return 0;
  314. }
  315.  
  316. #if 0
  317. BOOL CShellApp::InitInstance()
  318. {
  319.   CShellApp_app=this;
  320.   termine=termine_requested=shell_terminated=soft_term_requested=0;
  321.   
  322.   // Initialize OLE libraries
  323.   /*
  324.   if (!AfxOleInit())
  325.   {
  326.   AfxMessageBox(LANG(LANG_F1));
  327.   return FALSE;
  328.   }
  329.   AfxEnableControlContainer();
  330.   */
  331.   
  332.   // Fixer localisation dans la base de registre
  333.   //SetRegistryKey("WinHTTrack");
  334.   
  335.   // Standard initialization
  336.   // If you are not using these features and wish to reduce the size
  337.   //  of your final executable, you should remove from the following
  338.   //  the specific initialization routines you do not need.
  339.   /*
  340.   #ifdef _AFXDLL
  341.   Enable3dControls();            // Call this when using MFC in a shared DLL
  342.   #else
  343.   Enable3dControlsStatic();    // Call this when linking to MFC statically
  344.   #endif
  345.   */
  346.   
  347.   // Register the application's document templates.  Document templates
  348.   //  serve as the connection between documents, frame windows and views.
  349.   
  350.   // Change the registry key under which our settings are stored.
  351.   // You should modify this string to be something appropriate
  352.   // such as the name of your company or organization.
  353.   //SetRegistryKey(_T("Local AppWizard-Generated Applications"));
  354.   
  355.   //LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  356.   
  357.   // Register the application's document templates.  Document templates
  358.   //  serve as the connection between documents, frame windows and views.
  359.   
  360.   // Parse command line for standard shell commands, DDE, file open
  361.   /*CCommandLineInfo cmdInfo;
  362.   ParseCommandLine(cmdInfo);
  363.   */
  364.   
  365.   _Cinprogress_inst=NULL;
  366.   
  367.   LibRasUse=0;
  368.   
  369.   /*
  370.   #if USE_RAS
  371.   LibRas=new CDynamicRAS();
  372.   if (LibRas->IsRASLoaded()) 
  373.   LibRasUse=1;
  374.   else
  375.   LibRasUse=0;
  376.   #endif
  377.   */
  378.   
  379.   maintab = new CMainTab("WinHTTrack Website Copier");
  380.   
  381.   // PATCH-->
  382.   // ΘxΘcution..
  383.   init_lance();
  384.   
  385.   delete maintab;
  386.   maintab=NULL;
  387.   
  388.   // PATCH-->
  389.   /*
  390.   // Dispatch commands specified on the command line
  391.   if (!ProcessShellCommand(cmdInfo))
  392.         return FALSE;
  393.     
  394.       // The one and only window has been initialized, so show and update it.
  395.       m_pMainWnd->ShowWindow(SW_SHOW);
  396.       m_pMainWnd->UpdateWindow();
  397.   */  
  398.   
  399.   
  400.   return TRUE;
  401. }
  402. #endif
  403.  
  404. // PATCH-->
  405. // routines diverses
  406.  
  407. char* _SN(LLint n) {
  408.   static char str[256];
  409.   str[0]='\0';
  410.   sprintf(str,LLintP,(LLint)n);        /* 64-bit */
  411.   return str;
  412. }
  413.  
  414. // t existe-t-il comme rΘpertoire?
  415. int dir_check(char* t) {
  416.   int dir;
  417.   FILE* fp=fopen(t,"rb");
  418.   dir=(errno==13);  // is directory
  419.   if (fp) fclose(fp);
  420.   return dir;
  421. }
  422.  
  423. void check_temp(char* t,char* s) {
  424.   if (strlen(s)==0)
  425.     if (dir_check(t))
  426.       strcpy(s,t);
  427. }
  428.  
  429.  
  430.  
  431. // PATCH-->
  432. // Routines gestion dials
  433. // PatchΘ pour 100% dials
  434.  
  435.  
  436. void CShellApp::init_lance() {
  437.   hts_init();
  438.   htswrap_add("check-link",httrackengine_check);
  439.   htswrap_add("init",httrackengine_init);
  440.   htswrap_add("free",httrackengine_uninit);
  441.   htswrap_add("start",httrackengine_start);
  442.   htswrap_add("end",httrackengine_end);
  443.   htswrap_add("check-html",httrackengine_htmlcheck);
  444.   htswrap_add("change-options",httrackengine_chopt);
  445.   htswrap_add("loop",httrackengine_loop);
  446.   htswrap_add("query",httrackengine_query);
  447.   htswrap_add("query2",httrackengine_query2);
  448.   htswrap_add("query3",httrackengine_query3);
  449.   htswrap_add("pause",httrackengine_pause);
  450.   
  451.   termine=termine_requested=shell_terminated=soft_term_requested=0;
  452.   lance();             // Lancer miroir!
  453.   if (fp_debug) {
  454.     fprintf(fp_debug,"Building top index\r\n");
  455.     fflush(fp_debug);
  456.   }
  457.   Build_TopIndex();
  458. }
  459.  
  460. /* sauver profile */
  461. /* ask: demande confirmation, si cela vaut le coup */
  462. int Save_current_profile(int ask) {
  463.   CString winprofile;
  464.   if (ask) {
  465.     if ((dialog0->GetName().IsEmpty()) && (dialog1->m_urls.IsEmpty()))
  466.       return IDNO;
  467.     int r;
  468.     char msg[256];
  469.     sprintf(msg,"%s?\r\n%s",LANG_SAVEPROJECT,dialog0->GetName());
  470.     if ((r=AfxMessageBox(msg,MB_YESNOCANCEL)) != IDYES)
  471.       return r;
  472.   }
  473.   //
  474.   CWaitCursor wait;
  475.   
  476.   // sauver whtt
  477.   {
  478.     CString st=dialog0->GetBasePath()+dialog0->GetName()+".whtt";
  479.     FILE* fp=fopen(st,"wb");
  480.     if (fp) fclose(fp);
  481.   }
  482.   
  483.   // sauver ini
  484.   winprofile=dialog0->GetPath();
  485.   if (winprofile.GetLength()>0)
  486.     if ((winprofile.Right(1)!="/") && (winprofile.Right(1)!="\\"))
  487.       winprofile+="\\";
  488.     winprofile+="hts-cache\\";
  489.     {
  490.       char tempo[HTS_URLMAXSIZE*2];
  491.       int i;
  492.       strcpy(tempo,winprofile);
  493.       for(i=0;i<(int)strlen(tempo);i++)
  494.         if (tempo[i]=='\\')
  495.           tempo[i]='/';              
  496.         structcheck(tempo);
  497.     }
  498.     
  499.     winprofile+="winprofile.ini";
  500.     Write_profile(winprofile,0);
  501.     
  502.     // marquer document comme "sauvΘ"
  503.     if (this_CSplitterFrame)
  504.       this_CSplitterFrame->SetSaved();
  505.     
  506.     return IDYES;
  507. }
  508.  
  509. // reprise possible?
  510. int check_continue(char* pathlog) {
  511.   char path_log[256];
  512.   strcpy(path_log,pathlog);
  513.   if (strlen(path_log)>0)
  514.     if ((path_log[strlen(path_log)-1]!='/') && (path_log[strlen(path_log)-1]!='\\'))
  515.       strcat(path_log,"/");
  516.     if ((fexist(fconcat(path_log,"hts-cache/new.dat"))) && (fexist(fconcat(path_log,"hts-cache/new.ndx")))) {  // il existe dΘja un cache prΘcΘdent.. renommer
  517.       //if (fexist(fconcat(path_log,"hts-cache/doit.log"))) {    // un cache est prΘsent
  518.       return 1;
  519.       //}
  520.     }
  521.     if ((fexist(fconcat(path_log,"hts-cache/old.dat"))) && (fexist(fconcat(path_log,"hts-cache/old.ndx")))) {  // il existe dΘja un ancien cache prΘcΘdent.. renommer
  522.       return 1;
  523.     }
  524.     AfxMessageBox(LANG(LANG_F2 /*"There is no cache in the directory indicated\nWinHTTrack can not find any interrupted mirror!"*/),MB_OK+MB_ICONSTOP);
  525.     return 0;
  526. }
  527.  
  528.  
  529. void CShellApp::OptPannel() {
  530.   Write_profile("<mem>",0);       // enregistrer profile dans buffer local
  531.   if (maintab->DoModal()==IDCANCEL) {
  532.     Read_profile("<mem>",0);      // restaurer
  533.   }
  534. }
  535.  
  536.  
  537. #define ADD_MIME_IN_COPT(A) \
  538.   if(strlen(maintab->m_option11.m_ext##A)+strlen(maintab->m_option11.m_mime##A)) { \
  539.   strcat(buff_MIME,"--assume "); \
  540.   strcat(buff_MIME,maintab->m_option11.m_ext##A); \
  541.   strcat(buff_MIME,"="); \
  542.   strcat(buff_MIME,maintab->m_option11.m_mime##A); \
  543.   strcat(buff_MIME," "); \
  544.   } \
  545.   
  546. // parser maintab et calculer options
  547. void compute_options() { 
  548.   CWaitCursor wait;
  549.   
  550.   /* Effacer options */
  551.   LINE[0]
  552.     =OPTIONurl[0]
  553.     =OPTIONfilelist[0]
  554.     =OPTIONproxy[0]
  555.     =OPTIONport[0]
  556.     =OPTIONdepth[0]
  557.     =OPTIONextdepth[0]
  558.     =OPTIONget[0]
  559.     =OPTIONwhere[0]
  560.     =OPTIONmeth[0]
  561.     =OPTIONmaxfile[0]
  562.     =OPTIONmax[0]
  563.     =OPTIONfrag[0]
  564.     =OPTIONconn[0]
  565.     =OPTIONtog[0]
  566.     =OPTIONcache[0]
  567.     =OPTIONrobots[0]
  568.     =choixdeb[0]
  569.     =build[0]
  570.     =filtre[0]
  571.     =OPTIONindex[0]
  572.     =OPTIONindex2[0]
  573.     =OPTIONdos[0]
  574.     =OPTIONtime[0]
  575.     =OPTIONrate[0]
  576.     =OPTIONhostquit[0]
  577.     =OPTIONuser[0]
  578.     =OPTIONfooter[0]
  579.     =OPTIONlog[0]
  580.     =OPTIONtestall[0]
  581.     =OPTIONparseall[0]
  582.     =OPTIONlink[0]
  583.     =OPTIONpath[0]
  584.     =OPTIONretry[0]
  585.     =OPTIONerrpage[0]
  586.     =OPTIONexternal[0]
  587.     =OPTIONnopurge[0]
  588.     =OPTIONhidepwd[0]
  589.     =OPTIONhidequery[0]
  590.     =OPTIONcookies[0]
  591.     =OPTIONchecktype[0]
  592.     =OPTIONparsejava[0]
  593.     =OPTIONCache2[0]
  594.     =OPTIONlogtype[0]
  595.     =OPTIONnorecatch[0]
  596.     =OPTIONtoler[0]
  597.     =OPTIONupdhack[0]
  598.     =OPTIONhttp10[0]
  599.     =OPTIONwaittime[0]
  600.     =OPTIONmaxtime[0]
  601.     =OPTIONmaxrate[0]
  602.     =OPTIONmaxconn[0]
  603.     =OPTIONmaxlinks[0]
  604.     =OPTIONhh[0]
  605.     =OPTIONmm[0]
  606.     =OPTIONss[0]
  607.     =buff_filtres[0]
  608.     =buff_MIME[0]
  609.     =OPTION_RasString[0]
  610.     ='\0';
  611.   /* Effacer options */
  612.   
  613.   // Mode de miroir
  614.   switch(dialog1->m_todo) {
  615.   case CB_ERR: case 0:
  616.     strcpy(choixdeb,"w");
  617.     break;
  618.   case 1:
  619.     strcpy(choixdeb,"W");
  620.     break;
  621.   case 2:
  622.     strcpy(choixdeb,"g");
  623.     break;
  624.   case 3:
  625.     strcpy(choixdeb,"Y");
  626.     break;
  627.   case 4:
  628.     strcpy(choixdeb,"!");
  629.     break;
  630.   default:
  631.     if (dialog1->m_todo==dialog1->LAST_ACTION)
  632.       strcpy(choixdeb,"i");    // reprise
  633.     else
  634.       strcpy(choixdeb,"/");    // reprise cache prioritaire
  635.     break;
  636.   }
  637.   
  638.   // URLS
  639.   char trans[50000];
  640.   strcpy(trans,"");
  641.   strncat(trans,dialog1->m_urls,30000);
  642.   strcpy(OPTIONurl,connversion(trans));
  643.   // --- formation du path
  644.   strcpy(OPTIONpath,"\""); strcat(OPTIONpath,dialog0->GetPath0()); strcat(OPTIONpath,"\"");
  645.   strcat(OPTIONpath,",");
  646.   strcat(OPTIONpath,"\""); strcat(OPTIONpath,dialog0->GetPath0()); strcat(OPTIONpath,"\"");
  647.   
  648.   // filelist
  649.   {
  650.     CString st=dialog1->m_filelist;
  651.     st.TrimLeft();
  652.     st.TrimRight();
  653.     strcpy(OPTIONfilelist,st);
  654.   }
  655.   
  656.   // stocker Θtat et hh/mm/ss
  657.   strcpy(OPTIONhh,dialog2->m_hh);
  658.   strcpy(OPTIONmm,dialog2->m_mm);
  659.   strcpy(OPTIONss,dialog2->m_ss);
  660.   if (strlen(OPTIONhh)) {    // heure
  661.     int x,y,z;
  662.     sscanf(OPTIONhh,"%d",&x);
  663.     x=min(max(x,0),23);
  664.     sprintf(OPTIONhh,"%d",x);
  665.     //
  666.     sscanf(OPTIONmm,"%d",&y);
  667.     y=min(max(y,0),59);
  668.     sprintf(OPTIONmm,"%d",y);
  669.     //
  670.     sscanf(OPTIONss,"%d",&z);
  671.     z=min(max(z,0),59);
  672.     sprintf(OPTIONss,"%d",z);
  673.     //
  674.     strcpy(OPTIONwaittime,"");
  675.     {
  676.       char str[32];
  677.       strcpy(OPTIONwaittime,"#u");
  678.       sprintf(str,"%d",x*3600+y*60+z);
  679.       strcat(OPTIONwaittime,str);
  680.     }
  681.   }
  682.   strcpy(OPTION_RasString,dialog2->RasString);
  683.   OPTION_dial=dialog2->dial;
  684.   
  685.   if (choixdeb[0]=='/') {
  686.     strcpy(OPTIONcache,"C1");      // cache prio
  687.   } else {
  688.     if(!maintab->m_option3.m_cache) 
  689.       strcpy(OPTIONcache,"C0"); 
  690.     else 
  691.       strcpy(OPTIONcache,"C2");     // cache non prio 
  692.     //OPTIONcache[0]='\0'; 
  693.   }
  694.   
  695.   // ne pas recharger fichiers dΘja pris mais effacΘs
  696.   if(maintab->m_option9.m_norecatch) strcpy(OPTIONnorecatch,"%n"); else strcpy(OPTIONnorecatch,"");
  697.   
  698.   // proxy
  699.   strcpy(OPTIONproxy,maintab->m_option10.m_proxy);
  700.   strcpy(OPTIONport,maintab->m_option10.m_port);
  701.   
  702.   //depth
  703.   strcpy(OPTIONdepth,maintab->m_option5.m_depth);
  704.   strcpy(OPTIONextdepth,maintab->m_option5.m_depth2);
  705.   
  706.   if(!maintab->m_option9.m_index) strcpy(OPTIONindex,"I0"); else OPTIONindex[0]='\0'; 
  707.   if(!maintab->m_option9.m_index2) strcpy(OPTIONindex2,"%I0"); else strcpy(OPTIONindex2,"%I"); 
  708.   if(maintab->m_option2.m_dos) strcpy(OPTIONdos,"L0"); else OPTIONdos[0]='\0'; 
  709.   if(maintab->m_option2.m_iso9660) strcpy(OPTIONdos,"L2"); else OPTIONdos[0]='\0'; 
  710.   if(maintab->m_option1.m_testall) strcpy(OPTIONtestall,"t"); else OPTIONtestall[0]='\0'; 
  711.   if(maintab->m_option1.m_parseall) strcpy(OPTIONparseall,"%P"); else strcpy(OPTIONparseall,"%P0"); 
  712.   if(maintab->m_option1.m_link) strcpy(OPTIONlink,"n"); else OPTIONlink[0]='\0'; 
  713.   if(maintab->m_option1.m_htmlfirst) strcpy(OPTIONhtmlfirst,"p7"); else strcpy(OPTIONhtmlfirst,""); 
  714.   if(maintab->m_option2.m_errpage) strcpy(OPTIONerrpage,"o0"); else OPTIONerrpage[0]='\0'; 
  715.   if(maintab->m_option2.m_external) strcpy(OPTIONexternal,"x"); else OPTIONexternal[0]='\0'; 
  716.   if(maintab->m_option2.m_nopurge) strcpy(OPTIONnopurge,"X0"); else OPTIONnopurge[0]='\0'; 
  717.   if(maintab->m_option2.m_hidepwd) strcpy(OPTIONhidepwd,"%x"); else OPTIONhidepwd[0]='\0'; 
  718.   if(maintab->m_option2.m_hidequery) strcpy(OPTIONhidequery,"%q0"); else OPTIONhidequery[0]='\0'; 
  719.   
  720.   OPTIONrobots[0]='\0';
  721.   if(maintab->m_option8.m_robots==0) strcpy(OPTIONrobots,"s0"); 
  722.   else if(maintab->m_option8.m_robots==1) strcpy(OPTIONrobots,"s1"); 
  723.   else if(maintab->m_option8.m_robots==2) strcpy(OPTIONrobots,"s2"); 
  724.   
  725.   // cookies,checktype,parsejava
  726.   if(maintab->m_option8.m_cookies==0) strcpy(OPTIONcookies,"b0"); // else strcpy(OPTIONcookies,"b1");
  727.   if (maintab->m_option8.m_checktype>=0)
  728.     sprintf(OPTIONchecktype,"u%d",maintab->m_option8.m_checktype);
  729.   if(maintab->m_option8.m_parsejava==0) strcpy(OPTIONparsejava,"j0"); // else strcpy(OPTIONcookies,"j1");
  730.   if (maintab->m_option8.m_http10) strcpy(OPTIONhttp10,"%h");   // HTTP/1.0 notamment
  731.   if (maintab->m_option8.m_toler)  strcpy(OPTIONtoler,"%B");    // tolerent
  732.   if (maintab->m_option8.m_updhack)  strcpy(OPTIONupdhack,"%s");    // update hack
  733.   
  734.   // store all in cache,logtype
  735.   if(maintab->m_option9.m_Cache2!=0) strcpy(OPTIONCache2,"k");
  736.   if(maintab->m_option9.m_logtype==1) strcpy(OPTIONlogtype,"z");
  737.   else if(maintab->m_option9.m_logtype==2) strcpy(OPTIONlogtype,"Z");
  738.   if (maintab->m_option3.m_windebug) strcat(OPTIONlogtype,"%H");      // debug headers
  739.   
  740.   strcpy(build,"");
  741.   if      (maintab->m_option2.m_build==0) strcpy(build,"N0");
  742.   else if (maintab->m_option2.m_build==1) strcpy(build,"N1");
  743.   else if (maintab->m_option2.m_build==2) strcpy(build,"N2");
  744.   else if (maintab->m_option2.m_build==3) strcpy(build,"N3");
  745.   else if (maintab->m_option2.m_build==4) strcpy(build,"N4");
  746.   else if (maintab->m_option2.m_build==5) strcpy(build,"N5");
  747.   else if (maintab->m_option2.m_build==6) strcpy(build,"N100");
  748.   else if (maintab->m_option2.m_build==7) strcpy(build,"N101");
  749.   else if (maintab->m_option2.m_build==8) strcpy(build,"N102");
  750.   else if (maintab->m_option2.m_build==9) strcpy(build,"N103");
  751.   else if (maintab->m_option2.m_build==10) strcpy(build,"N104");
  752.   else if (maintab->m_option2.m_build==11) strcpy(build,"N105");
  753.   else if (maintab->m_option2.m_build==12) strcpy(build,"N99");
  754.   else if (maintab->m_option2.m_build==13) strcpy(build,"N199");
  755.   else if (maintab->m_option2.m_build==14) {
  756.     strcpy(build,"-N \"");
  757.     strcat(build,maintab->m_option2.Bopt.m_BuildString);
  758.     strcat(build,"\"");
  759.   }
  760.   
  761.   strcpy(filtre,"");
  762.   if      (maintab->m_option3.m_filter==0) strcpy(filtre,"p0");
  763.   else if (maintab->m_option3.m_filter==1) strcpy(filtre,"p1");
  764.   else if (maintab->m_option3.m_filter==2) strcpy(filtre,"p2");
  765.   else if (maintab->m_option3.m_filter==3) {    /* default */
  766.     if(!maintab->m_option1.m_htmlfirst) strcpy(filtre,"p3");
  767.   }
  768.   else if (maintab->m_option3.m_filter==4) strcpy(filtre,"p7");
  769.   //
  770.   if      (maintab->m_option3.m_travel==0) strcat(filtre,"S");
  771.   else if (maintab->m_option3.m_travel==1) strcat(filtre,"D");
  772.   else if (maintab->m_option3.m_travel==2) strcat(filtre,"U");
  773.   else if (maintab->m_option3.m_travel==3) strcat(filtre,"B");
  774.   //
  775.   if      (maintab->m_option3.m_travel2==0) strcat(filtre,"a");
  776.   else if (maintab->m_option3.m_travel2==1) strcat(filtre,"d");
  777.   else if (maintab->m_option3.m_travel2==2) strcat(filtre,"l");
  778.   else if (maintab->m_option3.m_travel2==3) strcat(filtre,"e");
  779.   //
  780.   if      (maintab->m_option3.m_travel3==0) strcat(filtre,"K0");
  781.   else if (maintab->m_option3.m_travel3==1) strcat(filtre,"K");
  782.   else if (maintab->m_option3.m_travel3==2) strcat(filtre,"K3");
  783.   else if (maintab->m_option3.m_travel3==3) strcat(filtre,"K4");
  784.  
  785.   if (maintab->m_option9.m_logf) strcpy(OPTIONlog,"f2"); else strcpy(OPTIONlog,"Q"); 
  786.   
  787.   if(maintab->m_option5.m_sizemax!=""){
  788.     strcpy(OPTIONmax,"M");
  789.     strcat(OPTIONmax,maintab->m_option5.m_sizemax);
  790.   } else strcpy(OPTIONmax,"");
  791.   
  792.   if(maintab->m_option5.m_pausebytes!=""){
  793.     strcpy(OPTIONfrag,"G");
  794.     strcat(OPTIONfrag,maintab->m_option5.m_pausebytes);
  795.   } else strcpy(OPTIONfrag,"");
  796.   
  797.   
  798.   if(maintab->m_option5.m_maxhtml!="" || maintab->m_option5.m_othermax!="" ){
  799.     strcpy(OPTIONmaxfile,"m");
  800.     if(maintab->m_option5.m_othermax!="") strcat(OPTIONmaxfile,maintab->m_option5.m_othermax);
  801.     else strcat(OPTIONmaxfile,"0");
  802.     if(maintab->m_option5.m_maxhtml!="") {strcat(OPTIONmaxfile,",");strcat(OPTIONmaxfile,maintab->m_option5.m_maxhtml);}
  803.     else {strcat(OPTIONmaxfile,",");strcat(OPTIONmaxfile,"0");}
  804.   } else strcpy(OPTIONmaxfile,"");
  805.   
  806.   if(strcmp(maintab->m_option4.m_connexion,"")!=0){
  807.     strcpy(OPTIONconn,"c");
  808.     strcat(OPTIONconn,maintab->m_option4.m_connexion);
  809.   } else strcpy(OPTIONconn,"");
  810.   
  811.   if(strcmp(maintab->m_option4.m_timeout,"")!=0){
  812.     strcpy(OPTIONtime,"T");
  813.     strcat(OPTIONtime,maintab->m_option4.m_timeout);
  814.   } else strcpy(OPTIONtime,"");
  815.   
  816.   // quitter host si timeout ou rate out
  817.   strcpy(OPTIONhostquit,"");
  818.   {
  819.     int a=0;
  820.     if (maintab->m_option4.m_remt)
  821.       a+=1;
  822.     if (maintab->m_option4.m_rems)
  823.       a+=2;
  824.     sprintf(OPTIONhostquit,"H%d",a);
  825.   }
  826.   
  827.   //--> max time
  828.   if(strcmp(maintab->m_option5.m_maxtime,"")!=0){
  829.     strcpy(OPTIONmaxtime,"E");
  830.     strcat(OPTIONmaxtime,maintab->m_option5.m_maxtime);
  831.   } else strcpy(OPTIONmaxtime,"");
  832.   
  833.   //--> max rate
  834.   if(strcmp(maintab->m_option5.m_maxrate,"")!=0){
  835.     strcpy(OPTIONmaxrate,"A");
  836.     strcat(OPTIONmaxrate,maintab->m_option5.m_maxrate);
  837.   } else strcpy(OPTIONmaxrate,"");
  838.   
  839.   if(strcmp(maintab->m_option5.m_maxconn,"")!=0){
  840.     strcpy(OPTIONmaxconn,"%c");
  841.     strcat(OPTIONmaxconn,maintab->m_option5.m_maxconn);
  842.   } else strcpy(OPTIONmaxconn,"");
  843.   
  844.   if(strcmp(maintab->m_option5.m_maxlinks,"")!=0){
  845.     strcpy(OPTIONmaxlinks,"#L");
  846.     strcat(OPTIONmaxlinks,maintab->m_option5.m_maxlinks);
  847.   } else strcpy(OPTIONmaxlinks,"");
  848.   
  849.   if(strcmp(maintab->m_option4.m_rate,"")!=0){
  850.     strcpy(OPTIONrate,"J");
  851.     strcat(OPTIONrate,maintab->m_option4.m_rate);
  852.   } else strcpy(OPTIONrate,"");
  853.   
  854.   if(strcmp(maintab->m_option6.m_user,"")!=0){
  855.     strcpy(OPTIONuser,"\"");
  856.     strcat(OPTIONuser,maintab->m_option6.m_user);
  857.     strcat(OPTIONuser,"\"");
  858.   } else strcpy(OPTIONuser,"");
  859.   
  860.   if(strcmp(maintab->m_option6.m_footer,"")!=0){
  861.     strcpy(OPTIONfooter,"\"");
  862.     strcat(OPTIONfooter,maintab->m_option6.m_footer);
  863.     strcat(OPTIONfooter,"\"");
  864.   } else strcpy(OPTIONfooter,"");
  865.   
  866.   if(strcmp(maintab->m_option4.m_retry,"")!=0){
  867.     strcpy(OPTIONretry,"R");
  868.     strcat(OPTIONretry,maintab->m_option4.m_retry);
  869.   } else strcpy(OPTIONretry,"");
  870.   
  871.   if(strcmp(maintab->m_option7.m_url2,"")!=0){
  872.     strcpy(buff_filtres,maintab->m_option7.m_url2);
  873.   } else strcpy(buff_filtres,"");
  874.   
  875.   
  876.   // MIME
  877.   buff_MIME[0]='\0';
  878.   ADD_MIME_IN_COPT(1)
  879.     ADD_MIME_IN_COPT(2)
  880.     ADD_MIME_IN_COPT(3)
  881.     ADD_MIME_IN_COPT(4)
  882.     ADD_MIME_IN_COPT(5)
  883.     ADD_MIME_IN_COPT(6)
  884.     ADD_MIME_IN_COPT(7)
  885.     ADD_MIME_IN_COPT(8)
  886.     
  887.     /* autres options: RAS */
  888.     if (dialog2->m_rasdisc)
  889.       disconnect=1;     /* dΘconnexion α la fin */
  890.     else
  891.       disconnect=0;
  892. }
  893.  
  894. // Les routines α dΘfinir:
  895. int __cdecl httrackengine_check(char* adr,char* fil,int status) {  // appelΘ par le wizard
  896.   return -1;
  897. }
  898. void __cdecl httrackengine_init() {    // appelΘ lors de l'init de HTTRACK, avant le dΘbut d'un miroir
  899. #if USE_RAS
  900.   has_started=0;
  901. #endif
  902.   httrackengine_loop(NULL,0,0,0,0,NULL,0);  // init
  903.   //printf("DEMARRAGE DU MIROIR DETECTE\n");  
  904. }
  905. void __cdecl httrackengine_uninit() {  // appelΘ en fin de miroir (peut Ωtre utile!!!)
  906. #if USE_RAS
  907.   if (LibRasUse) {        /* librairie RAS chargΘe */
  908.     if (disconnect) {     /* on doit dΘconnecter */
  909.       if (connected) {    /* on a initiΘ une connexion */
  910.         if (conn)
  911.           LibRas->RasHangUp(conn);
  912.       } else {            /* tout dΘconnecter */
  913.         // On coupe tout (non, pas bourrin)
  914.         DWORD size;
  915.         RASCONN* adr;
  916.         int count=256;
  917.         size = sizeof(RASCONN)*(count+2);
  918.         adr = (RASCONN*) (char*) calloc(size,1);
  919.         if (adr) {
  920.           DWORD ent;
  921.           int i;
  922.           for(i=0;i<count;i++) {
  923.             adr[i].dwSize=sizeof(RASCONN);
  924.             strcpy(adr[i].szEntryName,"");
  925.           }
  926.           if (LibRas->RasEnumConnections((RASCONN*) adr,&size,&ent) == 0) {
  927.             for(i=0;i<(int)ent;i++) {
  928.               LibRas->RasHangUp(adr[i].hrasconn);
  929.             }
  930.           }
  931.           free(adr);
  932.         }
  933.         
  934.       }
  935.     }
  936.   }
  937. #endif
  938. }
  939. int __cdecl httrackengine_start(void* dummy) {   // appelΘ lors du dΘmarrage du miroir (premiΦres requΦtes)
  940. #if USE_RAS
  941.   // connexion RAS
  942.   has_started=1;    // dΘmarrage
  943.   connected=0;
  944.   conn = NULL;
  945.   memset(&SInfo, 0, sizeof(SInfo));
  946.   if (LibRasUse) {
  947.     if (strlen(OPTION_RasString)>0) {    // sΘlection provider
  948.       if (!LibRas->RasDial(NULL,NULL,&OPTION_dial,NULL,NULL,&conn)) {
  949.         RASCONNSTATUS status;
  950.         do {
  951.           status.dwSize = sizeof(status);
  952.           LibRas->RasGetConnectStatus(conn,&status);
  953.           switch(status.rasconnstate) {
  954.           case RASCS_Connected : 
  955.             connected=1;
  956.             break;
  957.           case RASCS_Disconnected :
  958.             strcpy(connected_err,LANG(LANG_F3 /*"Could not connect to provider"*/));
  959.             connected=-1;
  960.             break;
  961.           }
  962.         } while(connected==0);
  963.       } else {
  964.         strcpy(connected_err,LANG(LANG_F3 /*"Could not connect to provider","Impossible d'Θtablir la connexion"*/));
  965.         connected=-1;
  966.         //termine=1;
  967.       }
  968.     }
  969.     //
  970.     if (connected != -1)  // si pas d'erreur RAS
  971.       return 1;
  972.     else
  973.       return 0;
  974.   } else
  975.     return 1;
  976. #else
  977.   return 1;
  978. #endif
  979. }
  980. int  httrackengine_end() {     // appelΘ lors de la fin du miroir (plus de liens α charger)
  981.   WHTT_LOCK();
  982.   termine=1;
  983.   if (_Cinprogress_inst) {
  984.     _Cinprogress_inst->EndDialog(IDOK);
  985.     _Cinprogress_inst=NULL;
  986.   }
  987.   WHTT_UNLOCK();
  988.   return 1;
  989. }
  990. int __cdecl httrackengine_htmlcheck(char* html,int len,char* url_adresse,char* url_fichier) {    // appelΘ α chaque fois qu'un html doit Ωtre scannΘ (utile pour la prospection mais inutile ici)
  991.   return 1;
  992. }
  993. int __cdecl httrackengine_chopt(void* opt) {
  994.   return 1;
  995. }
  996.  
  997. // Le routine la plus utile sans doute: elle refresh les tableaux
  998. // C'est la 2e routine en thread qui assure le refresh graphique
  999. // (plus efficace)
  1000. // -->C'est elle qui dΘcide de tout arrΩter si elle dΘtecte in termine_request<--
  1001. int __cdecl httrackengine_loop(
  1002.                                void* _back,int back_max,int back_index,
  1003.                                int lien_n,int lien_tot,
  1004.                                int stat_time,
  1005.                                hts_stat_struct* stats) {    // appelΘ α chaque boucle de HTTrack
  1006.   static char s[HTS_URLMAXSIZE*2]="";  // utilisΘ plus loin
  1007.   int stat_written=-1;
  1008.   int stat_updated=-1;
  1009.   int stat_errors=-1;
  1010.   int stat_warnings=-1;
  1011.   int stat_infos=-1;
  1012.   int nbk=-1;
  1013.   LLint nb=-1;
  1014.   int stat_nsocket=-1;
  1015.   LLint stat_bytes=-1;
  1016.   LLint stat_bytes_recv=-1;
  1017.   int irate=-1;
  1018.   
  1019.   WHTT_LOCK();
  1020.  
  1021.   if (stats) {
  1022.     stat_written=stats->stat_files;
  1023.     stat_updated=stats->stat_updated_files;
  1024.     stat_errors=stats->stat_errors;
  1025.     stat_warnings=stats->stat_warnings;
  1026.     stat_infos=stats->stat_infos;
  1027.     nbk=stats->nbk;
  1028.     stat_nsocket=stats->stat_nsocket;
  1029.     irate=(int)stats->rate;
  1030.     nb=stats->nb;
  1031.     stat_bytes=stats->nb;
  1032.     stat_bytes_recv=stats->HTS_TOTAL_RECV;
  1033.   }
  1034.   
  1035. #if !SHELL_MULTITHREAD
  1036.   static TStamp last_time;
  1037. #endif
  1038.   int rate;
  1039.   // casts
  1040.   lien_back* back=(lien_back*) _back;
  1041.   //  static int ft=-1;
  1042.   
  1043.   if (back_max == 0) {
  1044. #if !SHELL_MULTITHREAD
  1045.     last_time=0;
  1046. #endif
  1047.     // en cas de manque de time
  1048.     SInfo.stat_timestart=time_local();
  1049.     WHTT_UNLOCK();
  1050.     return 1;
  1051.   }
  1052.   
  1053.   if ((termine) || (termine_requested)) {
  1054.     SInfo.refresh=0;      // pas de refresh
  1055.     SInfo.refresh=0;      // pas de refresh
  1056.     termine_requested=1;
  1057.     WHTT_UNLOCK();
  1058.     return 0;
  1059.   }
  1060.   
  1061.   if (stat_written>=0) SInfo.stat_written=stat_written;
  1062.   if (stat_updated>=0) SInfo.stat_updated=stat_updated;
  1063.   if (stat_errors>=0)  SInfo.stat_errors=stat_errors;
  1064.   if (stat_warnings>=0)  SInfo.stat_warnings=stat_warnings;
  1065.   if (stat_infos>=0)  SInfo.stat_infos=stat_infos;
  1066.   
  1067. #if SHELL_MULTITHREAD 
  1068.   //if (((tl-last_time)>=100) || ((tl-last_time)<0)) {   // chaque 100 ms
  1069.   if (SInfo.ask_refresh) {
  1070. #else
  1071.     TStamp tl=0;
  1072.     {
  1073.       time_t tt;
  1074.       struct tm* A;
  1075.       tt=time(NULL);
  1076.       A=localtime(&tt);
  1077.       tl+=A->tm_sec;
  1078.       tl+=A->tm_min*60;
  1079.       tl+=A->tm_hour*60*60;
  1080.       //tl+=A->tm_yday*60*60*24;
  1081.       //tl+=A->tm_year*60*60*24*365;
  1082.       
  1083.       tl*=1000;  // en ms
  1084.       
  1085.       struct _timeb timebuffer;
  1086.       char *timeline;
  1087.       _ftime( &timebuffer );
  1088.       timeline = ctime( & ( timebuffer.time ) );
  1089.       
  1090.       tl+=timebuffer.millitm;    // + ms
  1091.     }
  1092.     if (((tl-last_time)>=HTS_SLEEP_WIN) || ((tl-last_time)<0)) {   // chaque 250 ms
  1093.       last_time=tl;
  1094. #endif
  1095.       //INFILLMEM_LOCKED=1;    // locker interface
  1096.       // OPTI int rate;
  1097.       SInfo.ask_refresh=0;
  1098.       
  1099.       // pour Θviter temps cpu consommΘ trop grand
  1100.       // Sleep(10);
  1101.       
  1102.       // initialiser ft
  1103.       if ((stat_nsocket==-1)) {
  1104.         if (SInfo.ft==-1) {
  1105.           SInfo.ft=stat_time;
  1106.         }
  1107.       }
  1108.       
  1109. #if !SHELL_MULTITHREAD
  1110.       //
  1111.       MSG msg;  
  1112.       if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE )) {     
  1113.         switch (msg.message) {
  1114.         case WM_COMMAND:        
  1115.           switch(msg.wParam) { 
  1116.           case ID_APP_ABOUT: {
  1117.             Cabout about;
  1118.             about.DoModal();                                    }
  1119.             break;
  1120.           case ID_APP_EXIT: case WM_CLOSE :
  1121.             termine_requested=1;
  1122.             break;
  1123.           case  WM_DESTROY: case WM_NCDESTROY: 
  1124.             termine_requested=1;
  1125.             break;
  1126.           }
  1127.           break;        
  1128.           default:
  1129.             DefWindowProc(msg.hwnd,msg.message,msg.wParam,msg.lParam);
  1130.             break;
  1131.         }
  1132.       }
  1133.       //
  1134. #endif
  1135.       
  1136.       // calculer heure si ce n'est dΘja fait
  1137.       if (stat_time<0)
  1138.         SInfo.stat_time=(int) (time_local()-SInfo.stat_timestart);
  1139.       
  1140.       // calculer transfer rate
  1141.       if ((stat_time>0) && (stat_bytes_recv>0))
  1142.         rate=(int)(stat_bytes_recv/stat_time);
  1143.       else
  1144.         rate=0;    // pas d'infos
  1145.       
  1146.       // stocker infos: octets transfΘrΘs, temps, etc.
  1147.       if (stat_bytes>=0) SInfo.stat_bytes=stat_bytes;      // bytes
  1148.       if (stat_time>=0) SInfo.stat_time=stat_time;         // time
  1149.       if (lien_tot>=0) SInfo.lien_tot=lien_tot; // nb liens
  1150.       if (lien_n>=0) SInfo.lien_n=lien_n;       // scanned
  1151.       SInfo.stat_nsocket=stat_nsocket;          // socks
  1152.       if (rate>0)  SInfo.rate=rate;                // rate
  1153.       if (irate>=0) SInfo.irate=irate;             // irate
  1154.       if (SInfo.irate<0) SInfo.irate=SInfo.rate;
  1155.       if (SInfo.stat_back>=0) SInfo.stat_back=nbk;
  1156.       
  1157.       // back: tableau de back_max ΘlΘments de cache
  1158.       // back_max: nombre d'ΘlΘments ^^^^
  1159.       // lien_tot: nombre total de liens traitΘs pour le moment
  1160.       // stat_bytes: octets sauvegardΘs
  1161.       // stat_bytes_recv: octets tΘlΘchargΘs
  1162.       // stat_time: temps en seconde depuis le dΘbut du miroir
  1163.       // stat_nsocket: nombre de sockets connectΘes actuellement
  1164.       // on peut en dΘduire rate=stat_bytes_recv/stat_time
  1165.       
  1166.       // printf("loop.. %d liens, %d octets, %d secondes, %d sockets, TAUX=%d\n",lien_tot,stat_bytes,stat_time,stat_nsocket,rate);
  1167.       
  1168.       // parcourir registre des liens
  1169.       if (back_index>=0) {  // seulement si index passΘ
  1170.         int j,k;
  1171.         int index=0;
  1172.         int ok=0;         // idem
  1173.         int l;            // idem
  1174.         int M=32;         // idem
  1175.         
  1176.         StatsBufferback=(void*) back;
  1177.         StatsBufferback_max=back_max;
  1178.         {
  1179.           int i;
  1180.           for(i=0;i<NStatsBuffer;i++) {
  1181.             strcpy(StatsBuffer[i].etat,"");
  1182.             strcpy(StatsBuffer[i].nom,"");
  1183.             strcpy(StatsBuffer[i].fichier,"");
  1184.             strcpy(StatsBuffer[i].url_sav,"");
  1185.             StatsBuffer[i].back=NULL;
  1186.             StatsBuffer[i].size=0;
  1187.             StatsBuffer[i].sizetot=0;
  1188.           }
  1189.         }
  1190.         for(k=0;k<2;k++) {    // 0: lien en cours 1: autres liens
  1191.           for(j=0;(j<3) && (index<NStatsBuffer);j++) {  // passe de prioritΘ
  1192.             int _i;
  1193.             for(_i=0+k;(_i< max(back_max*k,1) ) && (index<NStatsBuffer);_i++) {  // no lien
  1194.               int i=(back_index+_i)%back_max;    // commencer par le "premier" (l'actuel)
  1195.               if (back[i].status>=0) {     // signifie "lien actif"
  1196.                 // int ok=0;  // OPTI
  1197.                 ok=0;
  1198.                 switch(j) {
  1199.                 case 0:     // prioritaire
  1200.                   if ((back[i].status>0) && (back[i].status<99)) {
  1201.                     strcpy(StatsBuffer[index].etat,LANG(LANG_F4 /*"receive","rΘception"*/)); ok=1;
  1202.                   }
  1203.                   break;
  1204.                 case 1:
  1205.                   if (back[i].status==99) {
  1206.                     strcpy(StatsBuffer[index].etat,LANG(LANG_F5 /*"request","requΦte"*/)); ok=1;
  1207.                   }
  1208.                   else if (back[i].status==100) {
  1209.                     strcpy(StatsBuffer[index].etat,LANG(LANG_F6 /*"connect","connexion"*/)); ok=1;
  1210.                   }
  1211.                   else if (back[i].status==101) {
  1212.                     strcpy(StatsBuffer[index].etat,LANG(LANG_F7 /*"search","recherche"*/)); ok=1;
  1213.                   }
  1214.                   else if (back[i].status==1000) {    // ohh le beau ftp
  1215.                     sprintf(StatsBuffer[index].etat,"ftp: %s",back[i].info); ok=1;
  1216.                   }
  1217.                   else if (back[i].status==102) {         // SSL handshake
  1218.                     strcpy(StatsBuffer[index].etat,LANG(LANG_F6 /*"connect","connexion"*/)); ok=1;
  1219.                   }
  1220.                   break;
  1221.                 default:
  1222.                   if (back[i].status==0) {  // prΩt
  1223.                     if ((back[i].r.statuscode==200)) {
  1224.                       strcpy(StatsBuffer[index].etat,LANG(LANG_F8 /*"ready","prΩt"*/)); ok=1;
  1225.                     }
  1226.                     else if ((back[i].r.statuscode>=100) && (back[i].r.statuscode<=599)) {
  1227.                       char tempo[256]; tempo[0]='\0';
  1228.                       infostatuscode(tempo,back[i].r.statuscode);
  1229.                       strcpy(StatsBuffer[index].etat,tempo); ok=1;
  1230.                     }
  1231.                     else {
  1232.                       strcpy(StatsBuffer[index].etat,LANG(LANG_F9 /*"error","erreur"*/)); ok=1;
  1233.                     }
  1234.                   }
  1235.                   break;
  1236.                 }
  1237.                 
  1238.                 if (ok) {
  1239.                   // OPTI int l;
  1240.                   // OPTI int M=32;     // longueur
  1241.                   // OPTI char s[HTS_URLMAXSIZE*2]="";
  1242.                   //
  1243.                   StatsBuffer[index].back=i;        // index pour + d'infos
  1244.                   //
  1245.                   s[0]='\0';
  1246.                   strcpy(StatsBuffer[index].url_sav,back[i].url_sav);   // pour cancel
  1247.                   if (strcmp(back[i].url_adr,"file://"))
  1248.                     strcat(s,back[i].url_adr);
  1249.                   else
  1250.                     strcat(s,"localhost");
  1251.                   if (back[i].url_fil[0]!='/')
  1252.                     strcat(s,"/");
  1253.                   strcat(s,back[i].url_fil);
  1254.                   
  1255.                   StatsBuffer[index].fichier[0]='\0';
  1256.                   {
  1257.                     char* a=strrchr(s,'/');
  1258.                     if (a) {
  1259.                       strncat(StatsBuffer[index].fichier,a,200);
  1260.                       *a='\0';
  1261.                     }
  1262.                   }
  1263.                   
  1264.                   if ((l=strlen(s))<MAX_LEN_INPROGRESS)
  1265.                     strcpy(StatsBuffer[index].nom,s);
  1266.                   else {
  1267.                     // couper
  1268.                     StatsBuffer[index].nom[0]='\0';
  1269.                     strncat(StatsBuffer[index].nom,s,MAX_LEN_INPROGRESS/2-2);
  1270.                     strcat(StatsBuffer[index].nom,"...");
  1271.                     strcat(StatsBuffer[index].nom,s+l-MAX_LEN_INPROGRESS/2+2);
  1272.                   }
  1273.                   
  1274.                   //if (back[i].url_fil[0]!='/') printf("/");
  1275.                   
  1276.                   if (back[i].r.totalsize>0) {  // taille prΘdΘfinie
  1277.                     StatsBuffer[index].sizetot=back[i].r.totalsize;
  1278.                     StatsBuffer[index].size=back[i].r.size;
  1279.                   } else {  // pas de taille prΘdΘfinie
  1280.                     if (back[i].status==0) {  // prΩt
  1281.                       StatsBuffer[index].sizetot=back[i].r.size;
  1282.                       StatsBuffer[index].size=back[i].r.size;
  1283.                     } else {
  1284.                       StatsBuffer[index].sizetot=8192;
  1285.                       StatsBuffer[index].size=(back[i].r.size % 8192);
  1286.                     }
  1287.                   }
  1288.                   index++;
  1289.                 }
  1290.               }
  1291.             }
  1292.           }
  1293.         }
  1294.     }
  1295.     
  1296. #if SHELL_MULTITHREAD
  1297.     SInfo.refresh=1;     // on signale qu'il faut faire un refresh!
  1298. #else
  1299.     inprogress_refresh();  // tout de suite (non multithread)
  1300. #endif
  1301.     // INFILLMEM_LOCKED=0;    // dΘlocker interface
  1302.   }
  1303.   WHTT_UNLOCK();
  1304.   return (termine==0);
  1305. }
  1306.  
  1307. int inprogress_refresh() {
  1308.   static int toggle=0;
  1309.   // WHTT_LOCK(); // deja fait
  1310.   if ((!termine) && (!termine_requested) && (inprogress->m_hWnd)) {
  1311.     if (SInfo.refresh) {
  1312.       // INREDRAW_LOCKED=1;
  1313.       // REFRESH (si nb de socket==-1 on manage les fenetres)
  1314.       int icn;
  1315.       icn=inprogress->IsIconic();
  1316.       CString lnk;
  1317.       if (SInfo.stat_back)
  1318.         lnk.Format("%d/%d (+%d)",SInfo.lien_n,SInfo.lien_tot-1,SInfo.stat_back);
  1319.       else
  1320.         lnk.Format("%d/%d",SInfo.lien_n,SInfo.lien_tot-1);
  1321.       if (!icn) {
  1322.         int parsing=0;
  1323.         if (!soft_term_requested) {
  1324.           if (!hts_setpause(-1)) {
  1325.             if (!(parsing=hts_is_parsing(-1)))
  1326.               inprogress->SetDlgItemText(IDC_inforun,LANG(LANG_F10 /*"Receiving files.","RΘception des fichiers"*/)); 
  1327.             else {
  1328.               switch(hts_is_testing()) {
  1329.               case 0:
  1330.                 inprogress->SetDlgItemText(IDC_inforun,LANG(LANG_F11 /*"Parsing HTML file..","Parcours du fichier HTML"*/)); 
  1331.                 break;
  1332.               case 1:
  1333.                 inprogress->SetDlgItemText(IDC_inforun,LANG(LANG_F12 /*"Parsing HTML file (testing links)..","Parcours du fichier HTML (test des liens)"*/)); 
  1334.                 break;
  1335.               case 2:
  1336.                 inprogress->SetDlgItemText(IDC_inforun,LANG(LANG_F11b)); 
  1337.                 break;
  1338.               }
  1339.             }
  1340.           } else {
  1341.             if (((toggle++)/5)%2)
  1342.               inprogress->SetDlgItemText(IDC_inforun,LANG(LANG_F13 /*"Paused (select [File]/[Pause transfer] to continue)","Interrompu (choisir [Fichier]/[Interrompre transferts] pour continuer)"*/));
  1343.             else
  1344.               inprogress->SetDlgItemText(IDC_inforun,"");
  1345.           }
  1346.         } else {
  1347.           if (((toggle++)/5)%2)
  1348.             inprogress->SetDlgItemText(IDC_inforun,LANG(LANG_F13b));
  1349.           else
  1350.             inprogress->SetDlgItemText(IDC_inforun,"");
  1351.         }
  1352.         
  1353.         if (SInfo.stat_time>0) {
  1354.           char s[256];
  1355.           qsec2str(s,(TStamp) SInfo.stat_time);
  1356.           inprogress->SetDlgItemText(IDC_i1 ,s);  // time
  1357.         } else
  1358.           inprogress->SetDlgItemText(IDC_i1 , _SN(SInfo.stat_time) );  // time
  1359.         inprogress->SetDlgItemText(IDC_i0 , int2bytes(SInfo.stat_bytes) );  // bytes
  1360.         inprogress->SetDlgItemText(IDC_i2 , lnk);  // scanned
  1361.         if (SInfo.stat_nsocket>0)
  1362.           inprogress->SetDlgItemText(IDC_i3 , _SN(SInfo.stat_nsocket) );  // socks
  1363.         else
  1364.           inprogress->SetDlgItemText(IDC_i3 , "none" );  // wait
  1365.         
  1366.         CString st;
  1367.         st.Format("%s (%s)",int2bytessec(SInfo.irate),int2bytessec(SInfo.rate));
  1368.         inprogress->SetDlgItemText(IDC_i4 , st );  // rate
  1369.         
  1370.         inprogress->SetDlgItemText(IDC_i5 , _SN(SInfo.stat_errors) );
  1371.         inprogress->SetDlgItemText(IDC_i6 , _SN(SInfo.stat_written) );
  1372.         {
  1373.           char tempo[256];
  1374.           int pc=0;
  1375.           if (SInfo.stat_written)
  1376.             pc=(int)((SInfo.stat_updated*100)/(SInfo.stat_written));
  1377.           if (pc)
  1378.             sprintf(tempo,"%d (%d%%)",SInfo.stat_updated,pc);
  1379.           else
  1380.             sprintf(tempo,"%d",SInfo.stat_updated);
  1381.           inprogress->SetDlgItemText(IDC_i7 , tempo );
  1382.         }
  1383.         
  1384.         /*if (!parsing)*/
  1385.         {
  1386.           {
  1387.             int i;
  1388.             for(i=0;i<NStatsBuffer;i++) {
  1389.               if (StatsBuffer[i].sizetot>0) {
  1390.                 TStamp d = ((TStamp) StatsBuffer[i].size * 1000);
  1391.                 d = d / ((TStamp) StatsBuffer[i].sizetot);
  1392.                 StatsBuffer[i].offset = (int) d;
  1393.               } else
  1394.                 StatsBuffer[i].offset = 0;
  1395.             }
  1396.           }
  1397.           
  1398.           if (!parsing)
  1399.             inprogress->m_sl0.SetRange(0,1000);
  1400.           inprogress->m_sl1.SetRange(0,1000);
  1401.           inprogress->m_sl2.SetRange(0,1000);
  1402.           inprogress->m_sl3.SetRange(0,1000);
  1403.           inprogress->m_sl4.SetRange(0,1000);
  1404.           inprogress->m_sl5.SetRange(0,1000);
  1405.           inprogress->m_sl6.SetRange(0,1000);
  1406.           inprogress->m_sl7.SetRange(0,1000);
  1407.           inprogress->m_sl8.SetRange(0,1000);
  1408.           inprogress->m_sl9.SetRange(0,1000);
  1409.           inprogress->m_sl10.SetRange(0,1000);
  1410.           inprogress->m_sl11.SetRange(0,1000);
  1411.           inprogress->m_sl12.SetRange(0,1000);
  1412.           inprogress->m_sl13.SetRange(0,1000);
  1413.           
  1414.           if (!parsing)
  1415.             inprogress->m_sl0.SetPos(StatsBuffer[0].offset);
  1416.           inprogress->m_sl1.SetPos(StatsBuffer[1].offset);
  1417.           inprogress->m_sl2.SetPos(StatsBuffer[2].offset);
  1418.           inprogress->m_sl3.SetPos(StatsBuffer[3].offset);
  1419.           inprogress->m_sl4.SetPos(StatsBuffer[4].offset);
  1420.           inprogress->m_sl5.SetPos(StatsBuffer[5].offset);
  1421.           inprogress->m_sl6.SetPos(StatsBuffer[6].offset);
  1422.           inprogress->m_sl7.SetPos(StatsBuffer[7].offset);
  1423.           inprogress->m_sl8.SetPos(StatsBuffer[8].offset);
  1424.           inprogress->m_sl9.SetPos(StatsBuffer[9].offset);
  1425.           inprogress->m_sl10.SetPos(StatsBuffer[10].offset);
  1426.           inprogress->m_sl11.SetPos(StatsBuffer[11].offset);
  1427.           inprogress->m_sl12.SetPos(StatsBuffer[12].offset);
  1428.           inprogress->m_sl13.SetPos(StatsBuffer[13].offset);
  1429.           
  1430.           // redraw en boucle
  1431.           {
  1432.             int i=0;
  1433.             if (parsing)
  1434.               i++;
  1435.             for( ; i<NStatsBuffer;i++) {
  1436.               inprogress->element[0][i]->SetWindowText(StatsBuffer[i].etat);
  1437.               inprogress->element[1][i]->SetWindowText(StatsBuffer[i].nom);
  1438.               inprogress->element[4][i]->SetWindowText(StatsBuffer[i].fichier);
  1439.               
  1440.               if ((strlen(StatsBuffer[i].etat)==0) != StatsBuffer[i].actived) {
  1441.                 StatsBuffer[i].actived=!StatsBuffer[i].actived;
  1442.                 if (!StatsBuffer[i].actived)
  1443.                   inprogress->element[3][i]->ModifyStyle(WS_DISABLED,0);
  1444.                 else
  1445.                   inprogress->element[3][i]->ModifyStyle(0,WS_DISABLED);
  1446.                 inprogress->element[3][i]->RedrawWindow();
  1447.               }
  1448.             }
  1449.           }
  1450.           //
  1451.         }
  1452.         /* else*/
  1453.         if (parsing) {  // parsing
  1454.           //
  1455.           inprogress->m_sl0.SetRange(0,100);
  1456.           inprogress->m_sl0.SetPos(parsing);
  1457.           inprogress->element[0][0]->SetWindowText(LANG(LANG_F14 /*"scanning","parcours"*/));
  1458.           inprogress->element[1][0]->SetWindowText(StatsBuffer[0].nom);
  1459.           inprogress->element[4][0]->SetWindowText("");
  1460.           //inprogress->element[0][1]->SetWindowText();
  1461.         }
  1462.         
  1463.       }
  1464.       {
  1465.         static char last_info[256]="";
  1466.         char info[256];
  1467.         if ((SInfo.stat_nsocket==-1)) {
  1468. #if USE_RAS
  1469.           if (!has_started)
  1470. #endif
  1471.             inprogress->SetDlgItemText(IDC_nm0,LANG(LANG_F15 /*"Waiting for specific hour to start","Attente de l'heure programmΘe pour dΘmarrer"*/));
  1472. #if USE_RAS
  1473.           else
  1474.             inprogress->SetDlgItemText(IDC_nm0,LANG(LANG_F16 /*"Connecting to provider","Connexion au provider"*/));
  1475. #endif
  1476.           inprogress->m_sl0.SetRange(0,SInfo.ft);
  1477.           inprogress->m_sl0.SetPos(SInfo.ft-SInfo.stat_time);  // temps restant
  1478.           // inprogress->SetDlgItemText(IDC_nm1,_SN(ft));
  1479.           if (icn && (!this_CSplitterFrame->iconifie)) {  // minimisΘe mais pas en icone
  1480.             sprintf(info,"[%d s]",SInfo.stat_time);
  1481.           } else {
  1482.             sprintf(info,LANG(LANG_F17 /*"Mirror waiting [%d seconds]","Miroir en attente [%d secondes]"*/),SInfo.stat_time);
  1483.           }
  1484.         } else {
  1485.           if (icn) {  // minimisΘe
  1486.             sprintf(info,"[%s]",lnk);
  1487.           } else {
  1488.             sprintf(info,LANG(LANG_F18 /*"Mirror in progress [%s, %d bytes]","Miroir en cours [%s, %d octets]"*/),lnk,SInfo.stat_bytes);
  1489.           }
  1490.         }
  1491.         if (strcmp(info,last_info)) {       /* a changΘ */
  1492.           strcpy(last_info,info);           /* recopier */
  1493.           if (this_CSplitterFrame->iconifie)  // minimisΘ icone
  1494.             this_CSplitterFrame->IconChange(last_info);
  1495.           else
  1496.             this_app->GetMainWnd()->SetWindowText(last_info);
  1497.         }
  1498.       }  
  1499.       
  1500.       //inprogress->UpdateWindow();
  1501.     } else {
  1502.     }
  1503.   }
  1504.   // WHTT_UNLOCK();
  1505.   return 1;
  1506. }
  1507.  
  1508. /*
  1509. // refresh scan
  1510. int inprogress_refresh_scan() {
  1511. if ((!termine) && (!termine_requested) && (inprogress->m_hWnd)) {
  1512. if (!SInfo.refresh) {
  1513. if (!inprogress->IsIconic()) {
  1514. int n;
  1515. // patch pour le scanning
  1516. if (n=hts_is_parsing()) {
  1517. strcpy(StatsBuffer[0].etat,"scanning");
  1518. inprogress->element[0][0]->SetWindowText("scanning");
  1519. StatsBuffer[0].sizetot=100;
  1520. StatsBuffer[0].size=n;
  1521. inprogress->m_sl0.SetRange(0,100);  // progression en % du scanning
  1522. inprogress->m_sl0.SetPos(n);
  1523. //} else {
  1524. //  inprogress->element[0][0]->SetWindowText("...");
  1525. }
  1526. }
  1527. }
  1528. }
  1529. return 1;
  1530. }
  1531. */
  1532.  
  1533. /* Plantages si DoModal() dans un thread != du principal.. passons.. */
  1534. char* __cdecl httrackengine_query(char* question) {
  1535.   strcpy(WIZ_question,question);
  1536.   AfxGetMainWnd()->SendMessage(WM_COMMAND,wm_WizRequest1,0);
  1537.   return WIZ_reponse;
  1538. }
  1539.  
  1540. char* __cdecl httrackengine_query2(char* question) {
  1541.   strcpy(WIZ_question,question);
  1542.   AfxGetMainWnd()->SendMessage(WM_COMMAND,wm_WizRequest2,0);
  1543.   return WIZ_reponse;
  1544. }
  1545.  
  1546. char* __cdecl httrackengine_query3(char* question) {
  1547.   strcpy(WIZ_question,question);
  1548.   AfxGetMainWnd()->SendMessage(WM_COMMAND,wm_WizRequest3,0);
  1549.   return WIZ_reponse;
  1550. }
  1551.  
  1552. void __cdecl httrackengine_pause(char* lockfile) {
  1553.   AfxMessageBox("Engine paused.. click OK to continue!",MB_OK);
  1554.   remove(lockfile);
  1555. }
  1556.  
  1557. // modif RX 10/10/98 pour gestion des , et des tabs
  1558. char* connversion(char* chaine)
  1559. {
  1560.   for(int i=0;i < (int) strlen(chaine);i++) 
  1561.     if(chaine[i]=='\n') chaine[i]=' ';
  1562.     else if(chaine[i]==13) chaine[i]=' ';
  1563.     else if(chaine[i]==9) chaine[i]=' ';
  1564.     /*else if(chaine[i]==',') chaine[i]=' ';*/
  1565.     
  1566.     return chaine;
  1567. }
  1568.  
  1569.  
  1570. #if SHELL_MULTITHREAD
  1571. void __cdecl RunBackRobot(void* al_p) {
  1572.   int argc;
  1573.   char** argv;
  1574.   
  1575.   while((!inprogress) && (!termine)) Sleep(10);
  1576.   if (inprogress)
  1577.     while ((!inprogress->m_hWnd) || (termine)) Sleep(10);   // attendre formulaire
  1578.     //Sleep(100);
  1579.     
  1580.     Robot_params* al=(Robot_params*) al_p;
  1581.     argc = al->argc;
  1582.     argv = al->argv;
  1583.     /* launch the engine */
  1584.     hts_init();
  1585.     HTTRACK_result=hts_main(argc,argv);
  1586.     /* clear all vars */
  1587.     WHTT_LOCK();
  1588.     termine=1;
  1589.     WHTT_UNLOCK();
  1590.     hts_uninit();
  1591.     
  1592.     _endthread();
  1593. }
  1594. #endif
  1595.  
  1596. // modifs RX 10/10/98: gestion des ,
  1597. CString change(char* chaine,char c) {
  1598.   int comma=1; int first=1;
  1599.   CString chaine1;
  1600.   for(int i=0;i < (int) strlen(chaine);i++) {
  1601.     switch(chaine[i]) {
  1602.     case 10: case 13: case 9: case ' ': case ',':
  1603.       comma=1; 
  1604.       break;
  1605.     default:
  1606.       if (comma) {
  1607.         if (!first) chaine1 +=' ';
  1608.         else first=0; 
  1609.         chaine1  +=c; 
  1610.         comma=0;
  1611.       }
  1612.       chaine1 += chaine[i]; 
  1613.       break;
  1614.     }
  1615.   }
  1616.   return chaine1;
  1617. }
  1618.  
  1619.  
  1620. // Lancement
  1621. void lance(void) {
  1622.   char *argv[999];
  1623.   int argc=1;
  1624.   int g=0;
  1625.   int i =0;
  1626.   
  1627.   //
  1628.   if (fp_debug) {
  1629.     fprintf(fp_debug,"Building command line\r\n");
  1630.     fflush(fp_debug);
  1631.   }
  1632.   //
  1633.   LINE[0]='\0';
  1634.   strcpy(LINE,"-");
  1635.   if (choixdeb[0]!='W')
  1636.     strcat(LINE,"q");         // quiet
  1637.   
  1638.   if (choixdeb[0]=='/')
  1639.     strcat(LINE,"i");
  1640.   else if (choixdeb[0]!='!')
  1641.     strcat(LINE,choixdeb);
  1642.   // option de profondeur
  1643.   if(strcmp(OPTIONdepth,"")!=0) { 
  1644.     strcat(LINE,"r");
  1645.     strcat(LINE,OPTIONdepth);
  1646.   }
  1647.   if(strcmp(OPTIONextdepth,"")!=0) { 
  1648.     strcat(LINE,"%e");
  1649.     strcat(LINE,OPTIONextdepth);
  1650.   }
  1651.   if(strcmp(OPTIONcache,"")!=0) strcat(LINE,OPTIONcache);
  1652.   if(strcmp(OPTIONnorecatch,"")!=0) strcat(LINE,OPTIONnorecatch);
  1653.   if(strcmp(OPTIONtestall,"")!=0) strcat(LINE,OPTIONtestall);
  1654.   if(strcmp(OPTIONparseall,"")!=0) strcat(LINE,OPTIONparseall);
  1655.   if(strcmp(OPTIONlink,"")!=0) strcat(LINE,OPTIONlink);
  1656.   if(strcmp(OPTIONexternal,"")!=0) strcat(LINE,OPTIONexternal);
  1657.   if(strcmp(OPTIONnopurge,"")!=0) strcat(LINE,OPTIONnopurge);
  1658.   if(strcmp(OPTIONhidepwd,"")!=0) strcat(LINE,OPTIONhidepwd);
  1659.   if(strcmp(OPTIONhidequery,"")!=0) strcat(LINE,OPTIONhidequery);
  1660.   if(strcmp(OPTIONrobots,"")!=0) strcat(LINE,OPTIONrobots);
  1661.   if(strcmp(OPTIONcookies,"")!=0) strcat(LINE,OPTIONcookies);
  1662.   if(strcmp(OPTIONchecktype,"")!=0) strcat(LINE,OPTIONchecktype);
  1663.   if(strcmp(OPTIONparsejava,"")!=0) strcat(LINE,OPTIONparsejava);
  1664.   if(strcmp(OPTIONCache2,"")!=0) strcat(LINE,OPTIONCache2);
  1665.   if(strcmp(OPTIONlogtype,"")!=0) strcat(LINE,OPTIONlogtype);
  1666.   if (strlen(OPTIONhttp10)) strcat(LINE,OPTIONhttp10);
  1667.   if (strlen(OPTIONtoler)) strcat(LINE,OPTIONtoler);
  1668.   if (strlen(OPTIONupdhack)) strcat(LINE,OPTIONupdhack);
  1669.   
  1670.   // si get, ne pas faire
  1671.   if (strcmp(choixdeb,"g")!=0) {
  1672.     if(build[0]=='-') {
  1673.       strcat(LINE," ");
  1674.       strcat(LINE,build);
  1675.       strcat(LINE," -");
  1676.     } else if (strcmp(build,"")!=0) strcat(LINE,build);
  1677.   }
  1678.   strcat(LINE,OPTIONdos);
  1679.   strcat(LINE,OPTIONindex);
  1680.   strcat(LINE,OPTIONindex2);
  1681.   strcat(LINE,OPTIONhtmlfirst);
  1682.   strcat(LINE,filtre);
  1683.   strcat(LINE,OPTIONmax);
  1684.   strcat(LINE,OPTIONfrag);
  1685.   strcat(LINE,OPTIONmaxfile);
  1686.   strcat(LINE,OPTIONconn);
  1687.   strcat(LINE,OPTIONtime);
  1688.   strcat(LINE,OPTIONrate);
  1689.   strcat(LINE,OPTIONretry);
  1690.   strcat(LINE,OPTIONhostquit);
  1691.   strcat(LINE,OPTIONlog);
  1692.   strcat(LINE,OPTIONerrpage);
  1693.   //-->
  1694.   strcat(LINE,OPTIONwaittime);
  1695.   strcat(LINE,OPTIONmaxtime);
  1696.   strcat(LINE,OPTIONmaxrate);
  1697.   strcat(LINE,OPTIONmaxconn);
  1698.   strcat(LINE,OPTIONmaxlinks);
  1699.   strcat(LINE,"#f");  // flush
  1700.   
  1701.   if (strcmp(OPTIONuser,"")!=0) {strcat(LINE," ");strcat(LINE,"-F");strcat(LINE," ");strcat(LINE,OPTIONuser);}
  1702.   if (strcmp(OPTIONfooter,"")!=0) {strcat(LINE," ");strcat(LINE,"-%F");strcat(LINE," ");strcat(LINE,OPTIONfooter);}
  1703.   
  1704.   if ((int)strlen(OPTIONproxy)>0) {
  1705.     strcat(LINE," -P ");
  1706.     strcat(LINE,OPTIONproxy);
  1707.     strcat(LINE,":");
  1708.     strcat(LINE,OPTIONport);
  1709.   }
  1710.   
  1711.   if (strnotempty(LANGUAGE_ISO)) {
  1712.     strcat(LINE," -%l \"");
  1713.     strcat(LINE,LANGUAGE_ISO);
  1714.     if (strcmp(LANGUAGE_ISO,"en")!=0)
  1715.       strcat(LINE,", en");
  1716.     strcat(LINE,", *\"");
  1717.   }
  1718.   
  1719.   // mode spider, mettre aprΦs options
  1720.   if (choixdeb[0]=='!') {
  1721.     strcat(LINE," --testlinks");
  1722.   } else if (choixdeb[0]=='Y') {
  1723.     strcat(LINE," --mirrorlinks");
  1724.   }
  1725.   
  1726.   // URLs!!
  1727.   strcat(LINE," ");
  1728.   strcat(LINE,OPTIONurl);
  1729.   
  1730.   // file list
  1731.   if ((int) strlen(OPTIONfilelist)>0) {
  1732.     strcat(LINE," -%L \"");
  1733.     strcat(LINE,OPTIONfilelist);
  1734.     strcat(LINE,"\"");
  1735.   }
  1736.   
  1737.   // chemins
  1738.   if(strcmp(OPTIONpath,"")!=0) {
  1739.     strcat(LINE," ");
  1740.     strcat(LINE,"-O");
  1741.     strcat(LINE," ");
  1742.     strcat(LINE,OPTIONpath);
  1743.   }
  1744.   
  1745.   // buffer -> les + et -
  1746.   if(strcmp(buff_filtres,"")!=0) {
  1747.     //if(strcmp(diafiltre.m_url2 ,"")!=0) {
  1748.     strcat(LINE," ");
  1749.     strcat(LINE,buff_filtres );
  1750.   }
  1751.   
  1752.   // --assume
  1753.   if (strnotempty(buff_MIME)) {
  1754.     strcat(LINE," ");
  1755.     strcat(LINE,buff_MIME );
  1756.   }
  1757.   
  1758.   // ---
  1759.   
  1760.   //
  1761.   if (fp_debug) {
  1762.     fprintf(fp_debug,"Cleaning up command line and counting parameters\r\n");
  1763.     fflush(fp_debug);
  1764.   }
  1765.   //
  1766.   // Θpurer cr,lf,tab - double espace -> espace
  1767.   {
  1768.     char *a;
  1769.     while(a=strchr(LINE,9)) *a=' ';
  1770.     while(a=strchr(LINE,10)) *a=' ';
  1771.     while(a=strchr(LINE,13)) *a=' ';
  1772.     /* Eviter a cause des noms longs
  1773.     while(a=strstr(LINE," - ")) {     // options isolΘes sans rien
  1774.     char tempo[65535]; tempo[0]='\0';
  1775.     strncat(tempo,LINE,(int) a - (int) LINE);
  1776.     strcat(tempo,a+2);
  1777.     strcpy(LINE,tempo);
  1778.     }
  1779.     while(a=strstr(LINE,"  ")) {
  1780.     char tempo[65535]; tempo[0]='\0';
  1781.     strncat(tempo,LINE,(int) a - (int) LINE);
  1782.     strcat(tempo,a+1);
  1783.     strcpy(LINE,tempo);
  1784.     }
  1785.     */
  1786.   }
  1787.   
  1788.   char LINE_back[65535];
  1789.   strcpy(LINE_back,LINE);
  1790.   
  1791.   // couper en morceaux
  1792.   {
  1793.     char* p=LINE;
  1794.     argv[0]="winhttrack";
  1795.     do {
  1796.       argv[argc++]=p;
  1797.       p=next_token(p,0);    // prochain token
  1798.       if (p) {
  1799.         *p=0;    // octet nul (tableau)
  1800.         p++;
  1801.       }            
  1802.     } while(p!=NULL);
  1803.   }
  1804.   
  1805.   //
  1806.   if (fp_debug) {
  1807.     fprintf(fp_debug,"Checking doit.log\r\n");
  1808.     fflush(fp_debug);
  1809.   }
  1810.   //
  1811.   // Ok, on lance!
  1812.   if(!termine) {
  1813.     int result=0;
  1814.     {
  1815.       char path_log[HTS_URLMAXSIZE*2];
  1816.       strcpy(path_log,CShellApp_app->end_path_complete);
  1817.       if (strlen(path_log)>0)
  1818.         if ((path_log[strlen(path_log)-1]!='/') && (path_log[strlen(path_log)-1]!='\\'))
  1819.           strcat(path_log,"/");
  1820.         
  1821.         // on efface le doit.log, pour annuler les parametres anciens et en redΘfinir de nouveaux
  1822.         // c'est ici une logique qui diffΦre de la version en ligne de commande
  1823.         //if ((fexist(fconcat(path_log,"hts-cache/new.dat"))) && (fexist(fconcat(path_log,"hts-cache/new.ndx")))) {  // il existe dΘja un cache prΘcΘdent.. renommer
  1824.         if (fexist(fconcat(path_log,"hts-cache/new.ndx"))) {    // un cache est prΘsent
  1825.           if (fexist(fconcat(path_log,"hts-cache/doit.log")))
  1826.             remove(fconcat(path_log,"hts-cache/doit.log"));
  1827.           FILE* fp=fopen(fconcat(path_log,"hts-cache/doit.log"),"wb");
  1828.           if (fp) fclose(fp);
  1829.         }
  1830.         //}
  1831.     }
  1832.     
  1833.     
  1834.     // ---
  1835.     // LANCER LE MIROIR
  1836.     // ---
  1837.     //
  1838.     if (fp_debug) {
  1839.       fprintf(fp_debug,"Ready to call httrack engine, launching threads\r\n");
  1840.       fflush(fp_debug);
  1841.     }
  1842.     //
  1843. #if SHELL_MULTITHREAD
  1844.     Robot_params al;
  1845.     al.argc=argc;
  1846.     al.argv=argv;
  1847.     _beginthread( RunBackRobot     , 0, (void*) &al);
  1848.     //_beginthread( RefreshBackRobot , 0, NULL);
  1849.     
  1850.     //
  1851.     if (fp_debug) {
  1852.       fprintf(fp_debug,"Threads launched, displaying main dialog\r\n");
  1853.       fflush(fp_debug);
  1854.     }
  1855.     //
  1856.     // domodal du refresh
  1857.     /* XXC A SUPPRIMER */
  1858.     while(!termine) {
  1859.       Sleep(100);
  1860.     }
  1861.     //inprogress->DoModal();
  1862.     WHTT_LOCK();
  1863.     shell_terminated=1;
  1864.     result=HTTRACK_result;
  1865.     termine=1;  
  1866.     WHTT_UNLOCK();
  1867.     //
  1868.     if (fp_debug) {
  1869.       fprintf(fp_debug,"Main dialog exited\r\n");
  1870.       fflush(fp_debug);
  1871.     }
  1872.     //
  1873.     
  1874.     // non multithread
  1875. #else
  1876. #error "Non supportΘ"
  1877. #endif
  1878.  
  1879.     /* Aborted mirror or finished? */
  1880.     {
  1881.       char path_log[HTS_URLMAXSIZE*2];
  1882.       strcpy(path_log,CShellApp_app->end_path_complete);
  1883.       if (strlen(path_log)>0)
  1884.         if ((path_log[strlen(path_log)-1]!='/') && (path_log[strlen(path_log)-1]!='\\'))
  1885.           strcat(path_log,"/");
  1886.         if (soft_term_requested || termine_requested) {
  1887.           FILE* fp=fopen(fconcat(path_log,"hts-cache/interrupted.lock"),"wb");
  1888.           if (fp)
  1889.             fclose(fp);
  1890.         } else
  1891.           remove(fconcat(path_log,"hts-cache/interrupted.lock"));
  1892.     }
  1893.     
  1894.     //SetForegroundWindow();   // yop en premier plan!
  1895.     //
  1896.     if (fp_debug) {
  1897.       fprintf(fp_debug,"Displaying end dialog\r\n");
  1898.       fflush(fp_debug);
  1899.     }
  1900.     //
  1901.     /* New pannel */
  1902.     if (result) {      // erreur?
  1903.       strcpy(end_mirror_msg,LANG(LANG_F19 /*"A problem occured during the mirror\n  \"","Un problΦme est survenu pendant le miroir\n  \""*/));
  1904.       strcat(end_mirror_msg,"\"");
  1905.       strcat(end_mirror_msg,hts_errmsg());
  1906.       strcat(end_mirror_msg,"\"");
  1907.       strcat(end_mirror_msg,LANG(LANG_F20 /*"\" \nDuring:\n  ","\" \nDurant:\n  "*/));
  1908.       strcat(end_mirror_msg,"\"");
  1909.       strcat(end_mirror_msg,LINE_back);
  1910.       strcat(end_mirror_msg,"\"");
  1911.       strcat(end_mirror_msg,LANG(LANG_F21 /*"\nSee the log file if necessary.\n\nClick OK to quit WinHTTrack.\n\nThanks for using WinHTTrack!","\nVoir le fichier log au besoin\n\nCliquez sur OK pour quitter WinHTTrack\n\nMerci d'utiliser WinHTTrack."*/));
  1912.       //AfxMessageBox(s,MB_OK+MB_ICONINFORMATION);
  1913.     } else {
  1914.       strcpy(end_mirror_msg,LANG(LANG_F22 /*"The mirror is finished.\nClick OK to quit WinHTTrack.\nSee log file(s) if necessary to ensure that everything is OK.\n\nThanks for using WinHTTrack!","Le miroir est terminΘ\nCliquez sur OK pour quitter WinHTTrack\nVoir au besoin les fichiers d'audit pour vΘrifier que tout s'est bien passΘ\n\nMerci d'utiliser WinHTTrack!"*/));
  1915.       //AfxMessageBox("The mirror is finished.\nClic OK to quit WinHTTrack.\nSee log file(s) if necessary to ensure that everything is OK.\n\nThanks for using WinHTTrack!",MB_OK+MB_ICONINFORMATION);
  1916.       //        ShellExecute(0,"open",,"","",);
  1917.     }
  1918. #if USE_RAS
  1919.     // erreur ras
  1920.     if (connected == -1)
  1921.       if ((int) strlen(connected_err) > 0)
  1922.         strcpy(end_mirror_msg,connected_err);
  1923. #endif
  1924.       {
  1925.         char pathlog[HTS_URLMAXSIZE*2];
  1926.         strcpy(pathlog,dialog0->GetPath());
  1927.         Ciplog form;
  1928.         if (strlen(pathlog)>0)
  1929.           if ((pathlog[strlen(pathlog)-1]!='/') && (pathlog[strlen(pathlog)-1]!='\\'))
  1930.             strcat(pathlog,"/");
  1931.           // fichier log existe ou on est tΘlΘcommandΘ par un !
  1932.           if ( (fsize(fconcat(pathlog,"hts-err.txt")))>0) {
  1933.             strcat(end_mirror_msg,LANG(LANG_F23 /*"\n\nTip: Click [View log file] to see warning or error messages","\n\nConseil: [Voir fichiers log] pour voir les erreurs et messages"*/));
  1934.           }
  1935.       }
  1936.       //this_Cinfoend->m_infoend = msg;
  1937.       inprogress->SendMessage(WM_USER + 4);      // avertir
  1938.       if (fp_debug) {
  1939.         fprintf(fp_debug,"DoModal end dialog, waiting\r\n");
  1940.         fflush(fp_debug);
  1941.       }
  1942.       /*
  1943.       if (info.DoModal() == IDC_NewProject) {     // relancer programme!
  1944.       // copie de onnewproject() de wid1::
  1945.       CWinApp* pApp = AfxGetApp();
  1946.       CString name = pApp->m_pszHelpFilePath;
  1947.       name=name.Left(name.GetLength()-4);
  1948.       name += ".EXE";
  1949.       ShellExecute(NULL,"open",name,"","",SW_RESTORE);    
  1950.       }
  1951.       */
  1952.       if (fp_debug) {
  1953.         fprintf(fp_debug,"Final info OK, leaving..\r\n");
  1954.         fflush(fp_debug);
  1955.       }
  1956.   }
  1957.   else {
  1958.   }
  1959.   
  1960. }
  1961.  
  1962. // int LANG_T(int);
  1963. // char* LANG(char* english,char* francais);
  1964.  
  1965.  
  1966. /* interface lang - lang_string="stringlang0\nstringlang1\n..laststring" */
  1967. void SetCombo(CWnd* _this,int id,char* lang_string) {
  1968.   CComboBox* combo = (CComboBox*) _this->GetDlgItem(id);
  1969.   CString st=lang_string;
  1970.   st.TrimLeft(); st.TrimRight();
  1971.   if (combo) {
  1972.     st+="\n";         /* end */
  1973.     combo->ResetContent();
  1974.     while(st.GetLength()) {
  1975.       int pos=st.Find('\n');
  1976.       CString item=st.Left(pos);
  1977.       st=st.Mid(pos+1);
  1978.       item.TrimLeft(); item.TrimRight();
  1979.       if (item.GetLength())
  1980.         combo->AddString(item);
  1981.     }
  1982.   }
  1983. }
  1984.  
  1985.  
  1986. // Ecriture profiles
  1987. char* profile_code(char* from) {
  1988.   static char buff[65535];
  1989.   int i;
  1990.   int j;
  1991.   for(i=0,j=0;i<(int) strlen(from);i++) {
  1992.     switch(from[i]) {
  1993.     case '%': 
  1994.       buff[j++]='%';
  1995.       buff[j++]='%';
  1996.       break;
  1997.     case '=': 
  1998.       buff[j++]='%';
  1999.       buff[j++]='3';
  2000.       buff[j++]='d';
  2001.       break;
  2002.     case 13:
  2003.       buff[j++]='%';
  2004.       buff[j++]='0';
  2005.       buff[j++]='d';
  2006.       break;
  2007.     case 10:
  2008.       buff[j++]='%';
  2009.       buff[j++]='0';
  2010.       buff[j++]='a';
  2011.       break;
  2012.     case 9:
  2013.       buff[j++]='%';
  2014.       buff[j++]='0';
  2015.       buff[j++]='9';
  2016.       break;
  2017.     default:
  2018.       buff[j++]=from[i];
  2019.       break;
  2020.     }
  2021.   }
  2022.   buff[j++]='\0';
  2023.   return buff;
  2024. }
  2025. char* profile_decode(char* from) {
  2026.   static char buff[2048];
  2027.   int i;
  2028.   int j;
  2029.   for(i=0,j=0;j<(int) strlen(from);i++) {  // oui oui
  2030.     if (from[j]=='%') {
  2031.       if (from[j+1]=='%') {
  2032.         buff[i]='%';
  2033.         j+=2;
  2034.       } else {
  2035.         if (strncmp(from+j+1,"0d",2)==0)
  2036.           buff[i]=13;
  2037.         else if (strncmp(from+j+1,"0a",2)==0)
  2038.           buff[i]=10;
  2039.         else if (strncmp(from+j+1,"09",2)==0)
  2040.           buff[i]=9;
  2041.         else if (strncmp(from+j+1,"3d",2)==0)
  2042.           buff[i]='=';
  2043.         else
  2044.           buff[i]=' ';
  2045.         j+=3;
  2046.       }
  2047.     } else
  2048.       buff[i]=from[j++];
  2049.   }
  2050.   buff[i++]='\0';
  2051.   return buff;
  2052. }
  2053. //
  2054. // Ecriture/Lecture profiles
  2055. int MyWriteProfileInt(CString path,CString dummy,CString name,int value) {
  2056.   if (path.IsEmpty()) {
  2057.     CWinApp* pApp = AfxGetApp();
  2058.     pApp->WriteProfileInt(dummy,name,value);
  2059.   } else if (path=="<mem>") {       // buffer
  2060.     tmpm.setInt(name,value);
  2061.     return 0;
  2062.   } else if (path=="<tmp>") {       // fichier temporaire commun
  2063.     if (tmpf) {
  2064.       return MyWriteProfileIntFile(tmpf,dummy,name,value);
  2065.     }
  2066.   } else {
  2067.     FILE* fp = fopen(path,"ab");
  2068.     if (fp) {
  2069.       int r=MyWriteProfileIntFile(fp,dummy,name,value);
  2070.       /*
  2071.       fprintf(fp,"%s=%d\x0d\x0a",name,value);
  2072.       */
  2073.       fclose(fp);
  2074.       return r;
  2075.     }
  2076.   }
  2077.   return 0;
  2078. }
  2079. int MyWriteProfileIntFile(FILE* fp,CString dummy,CString name,int value) {
  2080.   if (fp) {
  2081.     fprintf(fp,"%s=%d\x0d\x0a",name,value);
  2082.   }
  2083.   return 0;
  2084. }
  2085. int MyWriteProfileString(CString path,CString dummy,CString name,CString value) {
  2086.   if (path.IsEmpty()) {
  2087.     CWinApp* pApp = AfxGetApp();
  2088.     char *tempo;
  2089.     tempo=(char*) malloc(strlen(value)+1);
  2090.     if (tempo) {
  2091.       strcpy(tempo,value);
  2092.       pApp->WriteProfileString(dummy,name,profile_code(tempo));
  2093.     } else
  2094.       return -1;      // error
  2095.   } else if (path=="<mem>") {       // buffer
  2096.     tmpm.setString(name,value);
  2097.     return 0;
  2098.   } else if (path=="<tmp>") {       // fichier temporaire commun
  2099.     if (tmpf) {
  2100.       return MyWriteProfileStringFile(tmpf,dummy,name,value);
  2101.     }
  2102.   } else {
  2103.     FILE* fp = fopen(path,"ab");
  2104.     if (fp) {
  2105.       int r=MyWriteProfileStringFile(fp,dummy,name,value);
  2106.       /*
  2107.       char *tempo;
  2108.       tempo=(char*) malloc(strlen(value)+1);
  2109.       if (tempo) {
  2110.       strcpy(tempo,value);
  2111.       fprintf(fp,"%s=%s\x0d\x0a",name,profile_code(tempo));
  2112.       fclose(fp);
  2113.       free(tempo);
  2114.       } else
  2115.       return -1;      // error
  2116.       */
  2117.       fclose(fp);
  2118.       return r;
  2119.     }
  2120.   }
  2121.   return 0;
  2122. }
  2123. int MyWriteProfileStringFile(FILE* fp,CString dummy,CString name,CString value) {
  2124.   if (fp) {
  2125.     char *tempo;
  2126.     tempo=(char*) malloc(strlen(value)+1);
  2127.     if (tempo) {
  2128.       strcpy(tempo,value);
  2129.       fprintf(fp,"%s=%s\x0d\x0a",name,profile_code(tempo));
  2130.       free(tempo);
  2131.     } else
  2132.       return -1;      // error
  2133.   }
  2134.   return 0;
  2135. }
  2136. //
  2137. // lecture
  2138. int MyGetProfileInt(CString path,CString dummy,CString name,int value) {
  2139.   if (path.IsEmpty()) {
  2140.     CWinApp* pApp = AfxGetApp();
  2141.     return pApp->GetProfileInt(dummy,name,value);
  2142.   } else if (path=="<mem>") {       // buffer
  2143.     return tmpm.getInt(name,value);
  2144.   } else if (path=="<tmp>") {       // fichier temporaire commun
  2145.     if (tmpf) {
  2146.       return MyGetProfileIntFile(tmpf,dummy,name,value);
  2147.     } else return value;
  2148.   } else {
  2149.     FILE* fp = fopen(path,"rb");
  2150.     if (fp) {
  2151.       int r=MyGetProfileIntFile(fp,dummy,name,value);
  2152.       /*
  2153.       char srch[256];
  2154.       sprintf(srch,"%s=",name);
  2155.       while(!feof(fp)) {
  2156.       char s[HTS_URLMAXSIZE*2];
  2157.       linput(fp,s,1020);
  2158.       if (strncmp(s,srch,strlen(srch)) == 0) {    // ligne reconnue
  2159.       int val;
  2160.       if (sscanf(s+strlen(srch),"%d",&val) == 1)
  2161.       return val;
  2162.       else
  2163.       return value;
  2164.       }
  2165.       }
  2166.       fclose(fp);
  2167.       return value;
  2168.       */
  2169.       fclose(fp);
  2170.       return r;
  2171.     } else return value;
  2172.   }
  2173. }
  2174. int MyGetProfileIntFile(FILE* fp,CString dummy,CString name,int value) {
  2175.   if (fp) {
  2176.     char srch[256];
  2177.     fseek(fp,0,SEEK_SET);
  2178.     sprintf(srch,"%s=",name);
  2179.     while(!feof(fp)) {
  2180.       char s[2048]; s[0]='\0';
  2181.       linput(fp,s,2000);
  2182.       if (strlen(s)==0)     // EOF
  2183.         return value;
  2184.       if (strncmp(s,srch,strlen(srch)) == 0) {    // ligne reconnue
  2185.         int val;
  2186.         if (sscanf(s+strlen(srch),"%d",&val) == 1)
  2187.           return val;
  2188.         else
  2189.           return value;
  2190.       }
  2191.     }
  2192.     return value;
  2193.   } else return value;
  2194. }
  2195. CString MyGetProfileString(CString path,CString dummy,CString name,CString value) {
  2196.   if (path.IsEmpty()) {
  2197.     CWinApp* pApp = AfxGetApp();
  2198.     char tempo[32768];
  2199.     char value_default[32768];
  2200.     strcpy(value_default,value);
  2201.     strcpy(tempo,pApp->GetProfileString(dummy,name,profile_code(value_default)));
  2202.     return profile_decode(tempo);
  2203.   } else if (path=="<mem>") {       // buffer
  2204.     return tmpm.getString(name,value);
  2205.   } else if (path=="<tmp>") {       // fichier temporaire commun
  2206.     if (tmpf) {
  2207.       return MyGetProfileStringFile(tmpf,dummy,name,value);
  2208.     } else return value;
  2209.   } else {
  2210.     FILE* fp = fopen(path,"rb");
  2211.     if (fp) {
  2212.       CString st=MyGetProfileStringFile(fp,dummy,name,value);
  2213.       /*
  2214.       char srch[256];
  2215.       sprintf(srch,"%s",name);
  2216.       strcat(srch,"=");
  2217.       while(!feof(fp)) {
  2218.       char s[32768];
  2219.       linput(fp,s,32000);
  2220.       if (strncmp(s,srch,strlen(srch)) == 0) {    // ligne reconnue
  2221.       return profile_decode(s+strlen(srch));
  2222.       }
  2223.       }
  2224.       fclose(fp);
  2225.       return value;
  2226.       */
  2227.       fclose(fp);
  2228.       return st;
  2229.     } else return value;
  2230.   }
  2231. }
  2232. CString MyGetProfileStringFile(FILE* fp,CString dummy,CString name,CString value) {
  2233.   if (fp) {
  2234.     char srch[256];
  2235.     fseek(fp,0,SEEK_SET);
  2236.     sprintf(srch,"%s",name);
  2237.     strcat(srch,"=");
  2238.     while(!feof(fp)) {
  2239.       char s[32768]; s[0]='\0';
  2240.       linput(fp,s,32000);
  2241.       if (strlen(s)==0)     // EOF
  2242.         return value;
  2243.       if (strncmp(s,srch,strlen(srch)) == 0) {    // ligne reconnue
  2244.         return profile_decode(s+strlen(srch));
  2245.       }
  2246.     }
  2247.     return value;
  2248.   } else return value;
  2249. }
  2250.  
  2251. //
  2252. // Get_profile et Write_profile eux mΩmes
  2253. //
  2254. // path="" -> Θcrire dans la base (default)
  2255. // path="<tmp>" -> Θcrire dans le fichier tempo commun
  2256. // path="<mem>" -> Θcrire dans le buffer tempo commun
  2257. // path="<null>" -> lire default (illΘgal en Θcriture)
  2258. void Write_profile(CString path,int load_path) {
  2259.   CWaitCursor wait;
  2260.   CString strSection       = "OptionsValues";
  2261.   CString st;
  2262.   int n;
  2263.   
  2264.   // Fichier tempo ou fichier?
  2265.   if (path=="<tmp>") {     // fichier temporaire
  2266.     if (tmpf)
  2267.       fclose(tmpf);
  2268.     tmpf=tmpfile();
  2269.     if (!tmpf)
  2270.       return;
  2271.   } else if (path=="<mem>") {     // buffer temporaire
  2272.     tmpm.deleteAll();
  2273.   } else if (!(path.IsEmpty())) {
  2274.     FILE *fp=fopen(path,"wb");
  2275.     if (fp) 
  2276.       fclose(fp);
  2277.   }
  2278.   
  2279.   //if (dialog3.m_hWnd == NULL) {    // pas initialisΘ
  2280.   if (maintab->m_hWnd == NULL) {    // pas initialisΘ
  2281.     // checkboxes
  2282.     MyWriteProfileInt(path,strSection, "Near",maintab->m_option1.m_link);
  2283.     MyWriteProfileInt(path,strSection, "Test",maintab->m_option1.m_testall);
  2284.     MyWriteProfileInt(path,strSection, "ParseAll",maintab->m_option1.m_parseall);
  2285.     MyWriteProfileInt(path,strSection, "HTMLFirst",maintab->m_option1.m_htmlfirst);
  2286.     MyWriteProfileInt(path,strSection, "Cache",maintab->m_option3.m_cache);
  2287.     MyWriteProfileInt(path,strSection, "NoRecatch",maintab->m_option9.m_norecatch);
  2288.     MyWriteProfileInt(path,strSection, "Dos",
  2289.       ((maintab->m_option2.m_dos)?1:0)
  2290.       +
  2291.       (((maintab->m_option2.m_iso9660)?1:0)<<1)
  2292.       );
  2293.     MyWriteProfileInt(path,strSection, "Index",maintab->m_option9.m_index);
  2294.     MyWriteProfileInt(path,strSection, "WordIndex",maintab->m_option9.m_index2);
  2295.     MyWriteProfileInt(path,strSection, "Log",maintab->m_option9.m_logf);
  2296.     MyWriteProfileInt(path,strSection, "RemoveTimeout",maintab->m_option4.m_remt);
  2297.     MyWriteProfileInt(path,strSection, "RemoveRateout",maintab->m_option4.m_rems);
  2298.     MyWriteProfileInt(path,strSection, "FollowRobotsTxt",maintab->m_option8.m_robots);
  2299.     MyWriteProfileInt(path,strSection, "NoErrorPages",maintab->m_option2.m_errpage);
  2300.     MyWriteProfileInt(path,strSection, "NoExternalPages",maintab->m_option2.m_external);
  2301.     MyWriteProfileInt(path,strSection, "NoPwdInPages",maintab->m_option2.m_hidepwd);
  2302.     MyWriteProfileInt(path,strSection, "NoQueryStrings",maintab->m_option2.m_hidequery);
  2303.     MyWriteProfileInt(path,strSection, "NoPurgeOldFiles",maintab->m_option2.m_nopurge);
  2304.     MyWriteProfileInt(path,strSection, "Cookies",maintab->m_option8.m_cookies);
  2305.     MyWriteProfileInt(path,strSection, "CheckType",maintab->m_option8.m_checktype);
  2306.     MyWriteProfileInt(path,strSection, "ParseJava",maintab->m_option8.m_parsejava);
  2307.     MyWriteProfileInt(path,strSection, "HTTP10",maintab->m_option8.m_http10);
  2308.     MyWriteProfileInt(path,strSection, "TolerantRequests",maintab->m_option8.m_toler);
  2309.     MyWriteProfileInt(path,strSection, "UpdateHack",maintab->m_option8.m_updhack);
  2310.     MyWriteProfileInt(path,strSection, "StoreAllInCache",maintab->m_option9.m_Cache2);
  2311.     MyWriteProfileInt(path,strSection, "LogType",maintab->m_option9.m_logtype);
  2312.     MyWriteProfileInt(path,strSection, "UseHTTPProxyForFTP",maintab->m_option10.m_ftpprox);
  2313.     
  2314.     // menus
  2315.     MyWriteProfileInt(path,strSection, "Build",maintab->m_option2.m_build);
  2316.     MyWriteProfileInt(path,strSection, "PrimaryScan",maintab->m_option3.m_filter);
  2317.     MyWriteProfileInt(path,strSection, "Travel",maintab->m_option3.m_travel);
  2318.     MyWriteProfileInt(path,strSection, "GlobalTravel",maintab->m_option3.m_travel2);
  2319.     MyWriteProfileInt(path,strSection, "RewriteLinks",maintab->m_option3.m_travel3);
  2320.     MyWriteProfileString(path,strSection, "BuildString",maintab->m_option2.Bopt.m_BuildString);
  2321.     
  2322.     // champs
  2323.     MyWriteProfileString(path,strSection, "MaxHtml",maintab->m_option5.m_maxhtml);
  2324.     MyWriteProfileString(path,strSection, "MaxOther",maintab->m_option5.m_othermax);
  2325.     MyWriteProfileString(path,strSection, "MaxAll",maintab->m_option5.m_sizemax);
  2326.     MyWriteProfileString(path,strSection, "MaxWait",maintab->m_option5.m_pausebytes);
  2327.     MyWriteProfileString(path,strSection, "Sockets",maintab->m_option4.m_connexion);
  2328.     MyWriteProfileString(path,strSection, "Retry",maintab->m_option4.m_retry);
  2329.     MyWriteProfileString(path,strSection, "MaxTime",maintab->m_option5.m_maxtime);
  2330.     MyWriteProfileString(path,strSection, "TimeOut",maintab->m_option4.m_timeout);
  2331.     MyWriteProfileString(path,strSection, "RateOut",maintab->m_option4.m_rate);
  2332.     MyWriteProfileString(path,strSection, "UserID",maintab->m_option6.m_user);
  2333.     MyWriteProfileString(path,strSection, "Footer",maintab->m_option6.m_footer);
  2334.     MyWriteProfileString(path,strSection, "MaxRate",maintab->m_option5.m_maxrate);
  2335.     MyWriteProfileString(path,strSection, "WildCardFilters",maintab->m_option7.m_url2);
  2336.     MyWriteProfileString(path,strSection, "Proxy",maintab->m_option10.m_proxy);
  2337.     MyWriteProfileString(path,strSection, "Port",maintab->m_option10.m_port);
  2338.     MyWriteProfileString(path,strSection, "Depth",maintab->m_option5.m_depth);
  2339.     MyWriteProfileString(path,strSection, "ExtDepth",maintab->m_option5.m_depth2);
  2340.     MyWriteProfileString(path,strSection, "MaxConn",maintab->m_option5.m_maxconn);    
  2341.     MyWriteProfileString(path,strSection, "MaxLinks",maintab->m_option5.m_maxlinks);    
  2342.     
  2343.     // 11
  2344.     MyWriteProfileString(path,strSection, "MIMEDefsExt1",maintab->m_option11.m_ext1);    
  2345.     MyWriteProfileString(path,strSection, "MIMEDefsExt2",maintab->m_option11.m_ext2);    
  2346.     MyWriteProfileString(path,strSection, "MIMEDefsExt3",maintab->m_option11.m_ext3);    
  2347.     MyWriteProfileString(path,strSection, "MIMEDefsExt4",maintab->m_option11.m_ext4);    
  2348.     MyWriteProfileString(path,strSection, "MIMEDefsExt5",maintab->m_option11.m_ext5);    
  2349.     MyWriteProfileString(path,strSection, "MIMEDefsExt6",maintab->m_option11.m_ext6);    
  2350.     MyWriteProfileString(path,strSection, "MIMEDefsExt7",maintab->m_option11.m_ext7);    
  2351.     MyWriteProfileString(path,strSection, "MIMEDefsExt8",maintab->m_option11.m_ext8);    
  2352.     MyWriteProfileString(path,strSection, "MIMEDefsMime1",maintab->m_option11.m_mime1);    
  2353.     MyWriteProfileString(path,strSection, "MIMEDefsMime2",maintab->m_option11.m_mime2);    
  2354.     MyWriteProfileString(path,strSection, "MIMEDefsMime3",maintab->m_option11.m_mime3);    
  2355.     MyWriteProfileString(path,strSection, "MIMEDefsMime4",maintab->m_option11.m_mime4);    
  2356.     MyWriteProfileString(path,strSection, "MIMEDefsMime5",maintab->m_option11.m_mime5);    
  2357.     MyWriteProfileString(path,strSection, "MIMEDefsMime6",maintab->m_option11.m_mime6);    
  2358.     MyWriteProfileString(path,strSection, "MIMEDefsMime7",maintab->m_option11.m_mime7);    
  2359.     MyWriteProfileString(path,strSection, "MIMEDefsMime8",maintab->m_option11.m_mime8);    
  2360.   } else {
  2361.     // checkboxes
  2362.     // 1
  2363.     n=maintab->m_option1.IsDlgButtonChecked(IDC_link);
  2364.     MyWriteProfileInt(path,strSection,"Near", n);
  2365.     n=maintab->m_option1.IsDlgButtonChecked(IDC_testall);
  2366.     MyWriteProfileInt(path,strSection,"Test", n);
  2367.     n=maintab->m_option1.IsDlgButtonChecked(IDC_parseall);
  2368.     MyWriteProfileInt(path,strSection,"ParseAll", n);
  2369.     n=maintab->m_option1.IsDlgButtonChecked(IDC_htmlfirst);
  2370.     MyWriteProfileInt(path,strSection,"HTMLFirst", n);
  2371.     // 2
  2372.     n=maintab->m_option3.IsDlgButtonChecked(IDC_Cache);
  2373.     MyWriteProfileInt(path,strSection,"Cache", n);
  2374.     n=maintab->m_option2.IsDlgButtonChecked(IDC_norecatch);
  2375.     MyWriteProfileInt(path,strSection,"NoRecatch", n);
  2376.     n = ((maintab->m_option2.IsDlgButtonChecked(IDC_dos))?1:0)
  2377.       + ((maintab->m_option2.IsDlgButtonChecked(IDC_iso9660)?1:0)<<1);
  2378.     MyWriteProfileInt(path,strSection,"Dos", n);
  2379.     n=maintab->m_option2.IsDlgButtonChecked(IDC_index);
  2380.     MyWriteProfileInt(path,strSection,"Index", n);
  2381.     n=maintab->m_option2.IsDlgButtonChecked(IDC_index2);
  2382.     MyWriteProfileInt(path,strSection,"WordIndex", n);
  2383.     n=maintab->m_option2.IsDlgButtonChecked(IDC_logf);
  2384.     MyWriteProfileInt(path,strSection,"Log", n);
  2385.     n=maintab->m_option2.IsDlgButtonChecked(IDC_errpage);
  2386.     MyWriteProfileInt(path,strSection,"NoErrorPages", n);
  2387.     n=maintab->m_option2.IsDlgButtonChecked(IDC_hidepwd);
  2388.     MyWriteProfileInt(path,strSection,"NoPwdInPages", n);
  2389.     n=maintab->m_option2.IsDlgButtonChecked(IDC_hidequery);
  2390.     MyWriteProfileInt(path,strSection,"NoQueryStrings", n);
  2391.     n=maintab->m_option2.IsDlgButtonChecked(IDC_external);
  2392.     MyWriteProfileInt(path,strSection,"NoExternalPages", n);
  2393.     n=maintab->m_option2.IsDlgButtonChecked(IDC_nopurge);
  2394.     MyWriteProfileInt(path,strSection,"NoPurgeOldFiles", n);
  2395.     if ((n=maintab->m_option2.m_ctl_build.GetCurSel()) != CB_ERR)
  2396.       MyWriteProfileInt(path,strSection, "Build", n);
  2397.     st = maintab->m_option2.Bopt.m_BuildString;
  2398.     if (st.GetLength()>0)
  2399.       MyWriteProfileString(path,strSection, "BuildString",st);
  2400.     // 3
  2401.     // menus
  2402.     if ((n=maintab->m_option3.m_ctl_filter.GetCurSel()) != CB_ERR)
  2403.       MyWriteProfileInt(path,strSection, "PrimaryScan", n);
  2404.     if ((n=maintab->m_option3.m_ctl_travel.GetCurSel()) != CB_ERR)
  2405.       MyWriteProfileInt(path,strSection, "Travel", n);
  2406.     if ((n=maintab->m_option3.m_ctl_travel2.GetCurSel()) != CB_ERR)
  2407.       MyWriteProfileInt(path,strSection, "GlobalTravel", n);
  2408.     if ((n=maintab->m_option3.m_ctl_travel3.GetCurSel()) != CB_ERR)
  2409.       MyWriteProfileInt(path,strSection, "RewriteLinks", n);
  2410.     //
  2411.     maintab->m_option8.GetDlgItemText(IDC_robots,st);
  2412.     MyWriteProfileString(path,strSection, "FollowRobotsTxt", st);
  2413.     // 4
  2414.     maintab->m_option4.GetDlgItemText(IDC_connexion,st);
  2415.     MyWriteProfileString(path,strSection, "Sockets", st);
  2416.     maintab->m_option4.GetDlgItemText(IDC_timeout,st);
  2417.     MyWriteProfileString(path,strSection, "TimeOut", st);
  2418.     n=maintab->m_option4.IsDlgButtonChecked(IDC_remt);
  2419.     MyWriteProfileInt(path,strSection,"RemoveTimeout", n);
  2420.     maintab->m_option4.GetDlgItemText(IDC_retry,st);
  2421.     MyWriteProfileString(path,strSection, "Retry", st);
  2422.     maintab->m_option4.GetDlgItemText(IDC_rate,st);
  2423.     MyWriteProfileString(path,strSection, "RateOut", st);
  2424.     n=maintab->m_option4.IsDlgButtonChecked(IDC_rems);
  2425.     MyWriteProfileInt(path,strSection,"RemoveRateout", n);
  2426.     // 5
  2427.     maintab->m_option5.GetDlgItemText(IDC_maxhtml,st);
  2428.     MyWriteProfileString(path,strSection, "MaxHtml", st);
  2429.     maintab->m_option5.GetDlgItemText(IDC_othermax,st);
  2430.     MyWriteProfileString(path,strSection, "MaxOther", st);
  2431.     maintab->m_option5.GetDlgItemText(IDC_sizemax,st);
  2432.     MyWriteProfileString(path,strSection, "MaxAll", st);
  2433.     maintab->m_option5.GetDlgItemText(IDC_pausebytes,st);
  2434.     MyWriteProfileString(path,strSection, "MaxWait", st);
  2435.     maintab->m_option5.GetDlgItemText(IDC_maxtime,st);
  2436.     MyWriteProfileString(path,strSection, "MaxTime", st);
  2437.     maintab->m_option5.GetDlgItemText(IDC_maxrate,st);
  2438.     MyWriteProfileString(path,strSection, "MaxRate", st);
  2439.     maintab->m_option5.GetDlgItemText(IDC_depth,st);
  2440.     MyWriteProfileString(path,strSection,"Depth",st);
  2441.     maintab->m_option5.GetDlgItemText(IDC_depth2,st);
  2442.     MyWriteProfileString(path,strSection,"ExtDepth",st);
  2443.     maintab->m_option5.GetDlgItemText(IDC_maxconn,st);
  2444.     MyWriteProfileString(path,strSection, "MaxConn", st);
  2445.     maintab->m_option5.GetDlgItemText(IDC_maxlinks,st);
  2446.     MyWriteProfileString(path,strSection, "MaxLinks", st);
  2447.     // 6
  2448.     maintab->m_option6.GetDlgItemText(IDC_user,st);
  2449.     MyWriteProfileString(path,strSection, "UserID", st);
  2450.     maintab->m_option6.GetDlgItemText(IDC_footer,st);
  2451.     MyWriteProfileString(path,strSection, "Footer", st);
  2452.     // 7
  2453.     maintab->m_option7.GetDlgItemText(IDC_URL2,st);
  2454.     MyWriteProfileString(path,strSection, "WildCardFilters", st);
  2455.     // 8
  2456.     maintab->m_option8.GetDlgItemText(IDC_cookies,st);
  2457.     MyWriteProfileString(path,strSection, "Cookies", st);
  2458.     maintab->m_option8.GetDlgItemText(IDC_checktype,st);
  2459.     MyWriteProfileString(path,strSection, "CheckType", st);
  2460.     n=maintab->m_option8.IsDlgButtonChecked(IDC_parsejava);
  2461.     MyWriteProfileInt(path,strSection, "ParseJava", n);
  2462.     n=maintab->m_option8.IsDlgButtonChecked(IDC_http10);
  2463.     MyWriteProfileInt(path,strSection, "HTTP10", n);
  2464.     n=maintab->m_option8.IsDlgButtonChecked(IDC_toler);
  2465.     MyWriteProfileInt(path,strSection, "TolerantRequests", n);
  2466.     n=maintab->m_option8.IsDlgButtonChecked(IDC_updhack);
  2467.     MyWriteProfileInt(path,strSection, "UpdateHack", n);
  2468.     // 9
  2469.     maintab->m_option9.GetDlgItemText(IDC_Cache2,st);
  2470.     MyWriteProfileString(path,strSection, "StoreAllInCache", st);
  2471.     maintab->m_option9.GetDlgItemText(IDC_logtype,st);
  2472.     MyWriteProfileString(path,strSection, "LogType", st);
  2473.     // 10
  2474.     maintab->m_option10.GetDlgItemText(IDC_prox,st);
  2475.     MyWriteProfileString(path,strSection,"Proxy",st);
  2476.     maintab->m_option10.GetDlgItemText(IDC_proxport,st);
  2477.     MyWriteProfileString(path,strSection,"Port",st);
  2478.     n=maintab->m_option10.IsDlgButtonChecked(IDC_ftpprox);
  2479.     MyWriteProfileInt(path,strSection,"UseHTTPProxyForFTP", n);
  2480.     
  2481.     // 11
  2482.     maintab->m_option11.GetDlgItemText(IDC_ext1,st); MyWriteProfileString(path,strSection,"MIMEDefsExt1",st);
  2483.     maintab->m_option11.GetDlgItemText(IDC_ext2,st); MyWriteProfileString(path,strSection,"MIMEDefsExt2",st);
  2484.     maintab->m_option11.GetDlgItemText(IDC_ext3,st); MyWriteProfileString(path,strSection,"MIMEDefsExt3",st);
  2485.     maintab->m_option11.GetDlgItemText(IDC_ext4,st); MyWriteProfileString(path,strSection,"MIMEDefsExt4",st);
  2486.     maintab->m_option11.GetDlgItemText(IDC_ext5,st); MyWriteProfileString(path,strSection,"MIMEDefsExt5",st);
  2487.     maintab->m_option11.GetDlgItemText(IDC_ext6,st); MyWriteProfileString(path,strSection,"MIMEDefsExt6",st);
  2488.     maintab->m_option11.GetDlgItemText(IDC_ext7,st); MyWriteProfileString(path,strSection,"MIMEDefsExt7",st);
  2489.     maintab->m_option11.GetDlgItemText(IDC_ext8,st); MyWriteProfileString(path,strSection,"MIMEDefsExt8",st);
  2490.     maintab->m_option11.GetDlgItemText(IDC_mime1,st); MyWriteProfileString(path,strSection,"MIMEDefsMime1",st);
  2491.     maintab->m_option11.GetDlgItemText(IDC_mime2,st); MyWriteProfileString(path,strSection,"MIMEDefsMime2",st);
  2492.     maintab->m_option11.GetDlgItemText(IDC_mime3,st); MyWriteProfileString(path,strSection,"MIMEDefsMime3",st);
  2493.     maintab->m_option11.GetDlgItemText(IDC_mime4,st); MyWriteProfileString(path,strSection,"MIMEDefsMime4",st);
  2494.     maintab->m_option11.GetDlgItemText(IDC_mime5,st); MyWriteProfileString(path,strSection,"MIMEDefsMime5",st);
  2495.     maintab->m_option11.GetDlgItemText(IDC_mime6,st); MyWriteProfileString(path,strSection,"MIMEDefsMime6",st);
  2496.     maintab->m_option11.GetDlgItemText(IDC_mime7,st); MyWriteProfileString(path,strSection,"MIMEDefsMime7",st);
  2497.     maintab->m_option11.GetDlgItemText(IDC_mime8,st); MyWriteProfileString(path,strSection,"MIMEDefsMime8",st);
  2498.   }
  2499.   // liens, jokers etc. si mirror merge
  2500.   if (!(path.IsEmpty())) {
  2501.     if (dialog1->m_hWnd == NULL) {    // pas initialisΘ
  2502.       //MyWriteProfileString(path,strSection,"CurrentDepth",dialog1->m_depth);
  2503.       MyWriteProfileString(path,strSection,"CurrentUrl",dialog1->m_urls);
  2504.       if (dialog1->m_todo >= 0)
  2505.         MyWriteProfileInt(path, strSection,"CurrentAction", dialog1->m_todo);
  2506.       //
  2507.       MyWriteProfileString(path,strSection,"CurrentURLList",dialog1->m_filelist);
  2508.       
  2509.       //if (load_path) {
  2510.       //MyWriteProfileString(path,strSection,"CurrentPath1",dialog0->GetPath());
  2511.       //MyWriteProfileString(path,strSection,"CurrentPath2",dialog0->GetPath());
  2512.       //}
  2513.     } else {
  2514.       //dialog1->GetDlgItemText(IDC_depth,st);
  2515.       //MyWriteProfileString(path,strSection,"CurrentDepth",st);
  2516.       dialog1->GetDlgItemText(IDC_URL,st);
  2517.       MyWriteProfileString(path,strSection,"CurrentUrl",st);
  2518.       if ((n=dialog1->m_ctl_todo.GetCurSel()) != CB_ERR)
  2519.         MyWriteProfileInt(path,strSection, "CurrentAction", n);
  2520.       //
  2521.       dialog1->GetDlgItemText(IDC_filelist,st);
  2522.       MyWriteProfileString(path,strSection,"CurrentURLList",st);
  2523.       //
  2524.       //if (load_path) {
  2525.       //dialog1->GetDlgItemText(IDC_pathlog,st);
  2526.       //MyWriteProfileString(path,strSection,"CurrentPath1",st);
  2527.       //dialog1->GetDlgItemText(IDC_pthmir,st);
  2528.       //MyWriteProfileString(path,strSection,"CurrentPath2",st);
  2529.       //}
  2530.     }
  2531.   }
  2532. }
  2533. // path="" -> lire dans la base (default)
  2534. //if not exist: do not load anything but patches projname&co
  2535. void Read_profile(CString path,int load_path) {
  2536.   CWaitCursor wait;
  2537.   CString strSection       = "OptionsValues";
  2538.   CString st;
  2539.   
  2540.   // VΘrification <tmp>
  2541.   if (path=="<tmp>") {     // fichier temporaire
  2542.     if (!tmpf)
  2543.       return;
  2544.     else
  2545.       fflush(tmpf);
  2546.   } else if (path=="<null>") {     // options par dΘfaut
  2547.     path="<mem>";
  2548.     tmpm.deleteAll();              // effacer
  2549.   } else {
  2550.     int pos=path.ReverseFind('\\');
  2551.     if (pos>=0) {
  2552.       CString dir=path.Left(pos);           // enlever winprofile.ini
  2553.       pos=dir.ReverseFind('\\');
  2554.       if (pos>=0) {
  2555.         dir=dir.Left(pos);                  // enlever hts-cache
  2556.         pos=dir.ReverseFind('\\');
  2557.         if (pos>=0) {
  2558.           dialog0->m_projname=dir.Mid(pos+1);
  2559.           dialog0->m_projpath=dir.Left(pos);
  2560.           /*
  2561.           if (this_CWizTab)
  2562.           this_CWizTab->SetActivePage(2);     // page 3
  2563.           */
  2564.         }
  2565.       }
  2566.     }
  2567.   }
  2568.   
  2569.   // checkboxes
  2570.   maintab->m_option1.m_link      = MyGetProfileInt(path,strSection, "Near",0);
  2571.   maintab->m_option1.m_testall   = MyGetProfileInt(path,strSection, "Test",0);
  2572.   maintab->m_option1.m_parseall  = MyGetProfileInt(path,strSection, "ParseAll",1);
  2573.   maintab->m_option1.m_htmlfirst = MyGetProfileInt(path,strSection, "HTMLFirst",0);
  2574.   maintab->m_option3.m_cache     = MyGetProfileInt(path,strSection, "Cache",1);
  2575.   maintab->m_option9.m_norecatch = MyGetProfileInt(path,strSection, "NoRecatch",0);
  2576.   maintab->m_option2.m_dos       = (MyGetProfileInt(path,strSection, "Dos",0) & 1);
  2577.   maintab->m_option2.m_iso9660   = ((MyGetProfileInt(path,strSection, "Dos",0) & 2)>>1);
  2578.   maintab->m_option9.m_index     = MyGetProfileInt(path,strSection, "Index",1);
  2579.   maintab->m_option9.m_index2    = MyGetProfileInt(path,strSection, "WordIndex",0);
  2580.   maintab->m_option9.m_logf      = MyGetProfileInt(path,strSection, "Log",1);
  2581.   maintab->m_option4.m_remt      = MyGetProfileInt(path,strSection, "RemoveTimeout",0);
  2582.   maintab->m_option4.m_rems      = MyGetProfileInt(path,strSection, "RemoveRateout",0);
  2583.   maintab->m_option8.m_robots    = MyGetProfileInt(path,strSection, "FollowRobotsTxt",2);
  2584.   maintab->m_option2.m_errpage   = MyGetProfileInt(path,strSection, "NoErrorPages",0);
  2585.   maintab->m_option2.m_external  = MyGetProfileInt(path,strSection, "NoExternalPages",0);
  2586.   maintab->m_option2.m_hidepwd   = MyGetProfileInt(path,strSection, "NoPwdInPages",0);
  2587.   maintab->m_option2.m_hidequery = MyGetProfileInt(path,strSection, "NoQueryStrings",0);
  2588.   maintab->m_option2.m_nopurge   = MyGetProfileInt(path,strSection, "NoPurgeOldFiles",0);
  2589.   maintab->m_option8.m_cookies    = MyGetProfileInt(path,strSection, "Cookies",1);
  2590.   maintab->m_option8.m_checktype  = MyGetProfileInt(path,strSection, "CheckType",1);
  2591.   maintab->m_option8.m_parsejava  = MyGetProfileInt(path,strSection, "ParseJava",1);
  2592.   maintab->m_option8.m_toler      = MyGetProfileInt(path,strSection, "TolerantRequests",0);
  2593.   maintab->m_option8.m_updhack    = MyGetProfileInt(path,strSection, "UpdateHack",1);
  2594.   maintab->m_option8.m_http10     = MyGetProfileInt(path,strSection, "HTTP10",0);
  2595.   maintab->m_option9.m_Cache2     = MyGetProfileInt(path,strSection, "StoreAllInCache",0);
  2596.   maintab->m_option9.m_logtype    = MyGetProfileInt(path,strSection, "LogType",0);
  2597.   
  2598.   // menus
  2599.   maintab->m_option2.m_build   = MyGetProfileInt(path,strSection, "Build",0);
  2600.   maintab->m_option3.m_filter  = MyGetProfileInt(path,strSection, "PrimaryScan",3);
  2601.   maintab->m_option3.m_travel  = MyGetProfileInt(path,strSection, "Travel",1);
  2602.   maintab->m_option3.m_travel2 = MyGetProfileInt(path,strSection, "GlobalTravel",0);
  2603.   maintab->m_option3.m_travel3 = MyGetProfileInt(path,strSection, "RewriteLinks",0);
  2604.   maintab->m_option2.Bopt.m_BuildString = MyGetProfileString(path,strSection, "BuildString","%h%p/%n%q.%t");
  2605.   
  2606.   // champs
  2607.   maintab->m_option5.m_maxhtml =  MyGetProfileString(path,strSection, "MaxHtml");
  2608.   maintab->m_option5.m_othermax=  MyGetProfileString(path,strSection, "MaxOther");
  2609.   maintab->m_option5.m_sizemax =  MyGetProfileString(path,strSection, "MaxAll");
  2610.   maintab->m_option5.m_pausebytes=MyGetProfileString(path,strSection, "MaxWait");  
  2611.   maintab->m_option4.m_connexion= MyGetProfileString(path,strSection, "Sockets");
  2612.   maintab->m_option4.m_retry   =  MyGetProfileString(path,strSection, "Retry");
  2613.   maintab->m_option5.m_maxtime =  MyGetProfileString(path,strSection, "MaxTime");
  2614.   maintab->m_option4.m_timeout =  MyGetProfileString(path,strSection, "TimeOut");
  2615.   maintab->m_option4.m_rate    =  MyGetProfileString(path,strSection, "RateOut");
  2616.   maintab->m_option6.m_user    =  MyGetProfileString(path,strSection, "UserID","Mozilla/4.5 (compatible; HTTrack 3.0x; Windows 98)");
  2617.   maintab->m_option6.m_footer  =  MyGetProfileString(path,strSection, "Footer",HTS_DEFAULT_FOOTER);
  2618.   maintab->m_option5.m_maxrate =  MyGetProfileString(path,strSection, "MaxRate");
  2619.   maintab->m_option5.m_maxconn =  MyGetProfileString(path,strSection, "MaxConn");
  2620.   maintab->m_option5.m_maxlinks = MyGetProfileString(path,strSection, "MaxLinks");
  2621.   
  2622.   // 7
  2623.   maintab->m_option7.m_url2 = MyGetProfileString(path,strSection, "WildCardFilters","+*.png +*.gif +*.jpg +*.css +*.js -ad.doubleclick.net/*");
  2624.   
  2625.   // 10
  2626.   maintab->m_option10.m_proxy   = MyGetProfileString(path,strSection, "Proxy");
  2627.   maintab->m_option10.m_port    = MyGetProfileString(path,strSection, "Port");
  2628.   maintab->m_option10.m_ftpprox = MyGetProfileInt(path,strSection, "UseHTTPProxyForFTP",1);
  2629.   //
  2630.   maintab->m_option5.m_depth    = MyGetProfileString(path,strSection, "Depth");
  2631.   maintab->m_option5.m_depth2   = MyGetProfileString(path,strSection, "ExtDepth");
  2632.   
  2633.   // 11
  2634.   maintab->m_option11.m_ext1   = MyGetProfileString(path,strSection, "MIMEDefsExt1", "php3,php,php2,asp,jsp,pl,cfm");
  2635.   maintab->m_option11.m_ext2   = MyGetProfileString(path,strSection, "MIMEDefsExt2");
  2636.   maintab->m_option11.m_ext3   = MyGetProfileString(path,strSection, "MIMEDefsExt3");
  2637.   maintab->m_option11.m_ext4   = MyGetProfileString(path,strSection, "MIMEDefsExt4");
  2638.   maintab->m_option11.m_ext5   = MyGetProfileString(path,strSection, "MIMEDefsExt5");
  2639.   maintab->m_option11.m_ext6   = MyGetProfileString(path,strSection, "MIMEDefsExt6");
  2640.   maintab->m_option11.m_ext7   = MyGetProfileString(path,strSection, "MIMEDefsExt7");
  2641.   maintab->m_option11.m_ext8   = MyGetProfileString(path,strSection, "MIMEDefsExt8");
  2642.   maintab->m_option11.m_mime1   = MyGetProfileString(path,strSection, "MIMEDefsMime1", "text/html");
  2643.   maintab->m_option11.m_mime2   = MyGetProfileString(path,strSection, "MIMEDefsMime2");
  2644.   maintab->m_option11.m_mime3   = MyGetProfileString(path,strSection, "MIMEDefsMime3");
  2645.   maintab->m_option11.m_mime4   = MyGetProfileString(path,strSection, "MIMEDefsMime4");
  2646.   maintab->m_option11.m_mime5   = MyGetProfileString(path,strSection, "MIMEDefsMime5");
  2647.   maintab->m_option11.m_mime6   = MyGetProfileString(path,strSection, "MIMEDefsMime6");
  2648.   maintab->m_option11.m_mime7   = MyGetProfileString(path,strSection, "MIMEDefsMime7");
  2649.   maintab->m_option11.m_mime8   = MyGetProfileString(path,strSection, "MIMEDefsMime8");
  2650.   
  2651.   
  2652.   //st = MyGetProfileString(path,strSection,"WildCardFilters");
  2653.   //strcpy(buff_filtres,st);
  2654.   
  2655.   // liens, jokers etc. si mirror merge
  2656.   if (!(path.IsEmpty())) {
  2657.     if (dialog1->m_hWnd == NULL) {    // pas initialisΘ
  2658.       //dialog1->m_depth  = MyGetProfileString(path,strSection,"CurrentDepth");
  2659.       dialog1->m_urls     = MyGetProfileString(path,strSection,"CurrentUrl");
  2660.       dialog1->m_todo     = MyGetProfileInt(path,strSection,"CurrentAction",0);
  2661.       dialog1->m_filelist = MyGetProfileString(path,strSection,"CurrentURLList");
  2662.       /*
  2663.       if (load_path) {
  2664.       CString st;
  2665.       st = MyGetProfileString(path,strSection,"CurrentPath1");
  2666.       if (st != "")
  2667.       dialog1->m_pathlog = st;
  2668.       st = MyGetProfileString(path,strSection,"CurrentPath2");
  2669.       if (st != "")
  2670.       dialog1->m_pathmir = st;
  2671.       }
  2672.       */
  2673.     } else {
  2674.       //st = MyGetProfileString(path,strSection,"CurrentDepth");
  2675.       //dialog1->SetDlgItemText(IDC_depth,st);
  2676.       st = MyGetProfileString(path,strSection,"CurrentUrl");
  2677.       dialog1->SetDlgItemText(IDC_URL,st);
  2678.       int n = MyGetProfileInt(path,strSection,"CurrentAction",0);
  2679.       dialog1->m_ctl_todo.SetCurSel(n);
  2680.       st = MyGetProfileString(path,strSection,"CurrentURLList");
  2681.       dialog1->SetDlgItemText(IDC_filelist,st);
  2682.       /*
  2683.       if (load_path) {
  2684.       st = MyGetProfileString(path,strSection,"CurrentPath1");
  2685.       if (st != "")
  2686.       dialog1->SetDlgItemText(IDC_pathlog,st);
  2687.       st = MyGetProfileString(path,strSection,"CurrentPath2");
  2688.       if (st != "")
  2689.       dialog1->SetDlgItemText(IDC_pthmir,st);
  2690.       }
  2691.       */
  2692.       dialog1->Refresh();
  2693.     }
  2694.   }
  2695.   
  2696. }
  2697.  
  2698. // Initialisation du RAS
  2699. void InitRAS() {
  2700. #if USE_RAS
  2701.   if (!LibRas) {
  2702.     LibRas=new CDynamicRAS();
  2703.     if (LibRas->IsRASLoaded()) 
  2704.       LibRasUse=1;
  2705.     else
  2706.       LibRasUse=0;
  2707.   }
  2708. #endif
  2709. }
  2710.  
  2711. // Reconstruire index gΘnΘral!
  2712. void Build_TopIndex(BOOL check_empty) {
  2713.   CWaitCursor wait;
  2714.  
  2715.   // templates html
  2716.   /*
  2717.   char* toptemplate_header=readfile_or("templates/topindex-header.html",HTS_INDEX_HEADER);
  2718.   char* toptemplate_body=readfile_or("templates/topindex-body.html",HTS_INDEX_BODY);
  2719.   char* toptemplate_footer=readfile_or("templates/topindex-footer.html",HTS_INDEX_FOOTER);
  2720.   */
  2721.   
  2722.   //if (toptemplate_header && toptemplate_body && toptemplate_footer) {
  2723.   {
  2724.     char path[HTS_URLMAXSIZE*2];
  2725.     strcpy(path,CShellApp_app->end_path);
  2726.  
  2727.     /* Build top index */
  2728.     hts_buildtopindex(path, "");
  2729.  
  2730.     /* Check empty dirs and build .whtt */
  2731.     // FILE* fpo=fopen(fconcat(path,"/index.html"),"wb");
  2732.     //if (fpo) {
  2733.     {
  2734.       // verif_backblue(path);    // gΘnΘrer gif
  2735.       //
  2736.       // Header
  2737.       //fprintf(fpo,toptemplate_header,
  2738.       //  "<!-- Mirror and index made by HTTrack Website Copier/"HTTRACK_VERSION" "HTTRACK_AFF_AUTHORS" -->"
  2739.       //  );
  2740.       // chargement de la liste
  2741.       WIN32_FIND_DATA find;
  2742.       HANDLE h = FindFirstFile(CShellApp_app->end_path+"*.*",&find);
  2743.       if (h != INVALID_HANDLE_VALUE) {
  2744.         CString to_delete="";
  2745.         do {
  2746.           if (!(find.dwFileAttributes  & (FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN) ))
  2747.             if (strcmp(find.cFileName,".."))
  2748.               if (strcmp(find.cFileName,"."))
  2749.                 if (find.dwFileAttributes  & FILE_ATTRIBUTE_DIRECTORY ) {
  2750.                   int r;
  2751.                   r=CheckDirInfo(CShellApp_app->end_path+find.cFileName);
  2752.                   if ((r>=0) && (r<=3)) {       /* vide, fichiers vides etc */
  2753.                     to_delete+=(CShellApp_app->end_path+find.cFileName+"\n");
  2754.                   } else {      /* non vide */
  2755.                     char iname[HTS_URLMAXSIZE*2],iname2[HTS_URLMAXSIZE*2];
  2756.                     strcpy(iname,CShellApp_app->end_path);
  2757.                     strcat(iname,find.cFileName);
  2758.                     strcat(iname,"\\");
  2759.                     strcpy(iname2,iname);
  2760.                     strcat(iname,"index.html");
  2761.                     strcat(iname2,"\\hts-cache\\winprofile.ini");
  2762.                     if (fexist(iname)) {
  2763.                       char hname[HTS_URLMAXSIZE*2];
  2764.                       strcpy(hname,find.cFileName);
  2765.                       escape_check_url(hname);
  2766.                       // Body
  2767.                       //fprintf(fpo,toptemplate_body,
  2768.                       //  hname,
  2769.                       //  find.cFileName
  2770.                       //  );
  2771.                     }
  2772.                     
  2773.                     if ((fexist(iname)) || (fexist(iname2)) ) {
  2774.                       // vΘrifier existence de .whtt
  2775.                       strcpy(iname,CShellApp_app->end_path);
  2776.                       strcat(iname,find.cFileName);
  2777.                       strcat(iname,".whtt");
  2778.                       if (!fexist(iname)) {
  2779.                         FILE* fp=fopen(iname,"wb");
  2780.                         if (fp) fclose(fp);
  2781.                       }
  2782.                       
  2783.                     }
  2784.                   }
  2785.                 } else {    /* effacer .whtt qui ne pointent vers rien */
  2786.                   CString iname=CShellApp_app->end_path+find.cFileName;
  2787.                   if (iname.Right(5).CompareNoCase(".whtt")==0) {
  2788.                     CString rname=iname.Left(iname.GetLength()-5)+"\\index.html";
  2789.                     CString rname2=iname.Left(iname.GetLength()-5)+"\\hts-cache\\winprofile.ini";
  2790.                     if ( (!fexist((char*)LPCTSTR(rname))) && (!fexist((char*)LPCTSTR(rname2))) ) {
  2791.                       remove(iname);
  2792.                     }
  2793.                   }
  2794.                 }
  2795.         } while(FindNextFile(h,&find));
  2796.         FindClose(h);
  2797.         if (check_empty) {
  2798.           while(to_delete.GetLength()>0) {
  2799.             int pos=to_delete.Find('\n');
  2800.             if (pos) {
  2801.               CString path=to_delete.Left(pos);
  2802.               to_delete=to_delete.Mid(pos+1);
  2803.               CString str;
  2804.               str.Format(LANG_DELETEEMPTYCONF,path);
  2805.               if (AfxMessageBox(str,MB_OKCANCEL)==IDOK) {
  2806.                 /* Θliminer au besoin le .whtt */
  2807.                 DeleteFile(path+".whtt");
  2808.                 if (!RemoveEmptyDir(path))
  2809.                   AfxMessageBox(LANG_ERRORDEL);
  2810.               }
  2811.             } else
  2812.               to_delete="";
  2813.           }
  2814.         }
  2815.       }
  2816.       // Footer
  2817.       //fprintf(fpo,toptemplate_footer,
  2818.       //  "<!-- Mirror and index made by HTTrack Website Copier/"HTTRACK_VERSION" "HTTRACK_AFF_AUTHORS" -->"
  2819.       //  );
  2820.       //fclose(fpo);
  2821.     }
  2822.     
  2823.   }
  2824.  
  2825.   /*
  2826.   if (toptemplate_header)
  2827.     freet(toptemplate_header);
  2828.   if (toptemplate_body)
  2829.     freet(toptemplate_body);
  2830.   if (toptemplate_footer)
  2831.     freet(toptemplate_footer);
  2832.   */
  2833. }
  2834.  
  2835. /*
  2836. -1 : error
  2837. 0 : directory is empty
  2838. 1 : empty directories inside
  2839. 2 : empty files inside
  2840. 3 : 1 + 2
  2841. 4 : not empty
  2842. */
  2843. int CheckDirInfo(CString path) {
  2844.   CWaitCursor wait;
  2845.   
  2846.   if (path.Right(1)!="\\")
  2847.     path+="\\";
  2848.   
  2849.   // Pour FindFirstFile/FindNextFile
  2850.   WIN32_FIND_DATA find;
  2851.   HANDLE h = FindFirstFile(path+"*.*",&find);
  2852.   
  2853.   // accessible
  2854.   if (h!=INVALID_HANDLE_VALUE) {
  2855.     int return_code=0;
  2856.     do {
  2857.       if (!(find.dwFileAttributes  & FILE_ATTRIBUTE_SYSTEM )) {
  2858.         if (strcmp(find.cFileName,"..")) {
  2859.           if (strcmp(find.cFileName,".")) {
  2860.             if (find.dwFileAttributes  & FILE_ATTRIBUTE_DIRECTORY ) {
  2861.               return_code|=1;
  2862.               int r=CheckDirInfo(path+find.cFileName);
  2863.               if (r==4)
  2864.                 return_code=4;
  2865.               else
  2866.                 return_code|=r;
  2867.             } else {
  2868.               return_code|=2;
  2869.               if ((find.nFileSizeLow) || (find.nFileSizeHigh))
  2870.                 return_code=4;
  2871.             }
  2872.           }
  2873.         }
  2874.       }
  2875.     } while(FindNextFile(h,&find) && !((return_code & 4)) );
  2876.     FindClose(h);
  2877.     return return_code;
  2878.   } else
  2879.     return -1;
  2880. }
  2881.  
  2882. /*
  2883. Remove Empty Dir
  2884. */
  2885. BOOL RemoveEmptyDir(CString path) {
  2886.   CWaitCursor wait;
  2887.   
  2888.   SetCurrentDirectory("C:\\");
  2889.   
  2890.   if (path.Right(1)!="\\")
  2891.     path+="\\";
  2892.   
  2893.   // Pour FindFirstFile/FindNextFile
  2894.   WIN32_FIND_DATA find;
  2895.   HANDLE h = FindFirstFile(path+"*.*",&find);
  2896.   
  2897.   // accessible
  2898.   if (h!=INVALID_HANDLE_VALUE) {
  2899.     do {
  2900.       if (!(find.dwFileAttributes  & FILE_ATTRIBUTE_SYSTEM )) {
  2901.         if (strcmp(find.cFileName,"..")) {
  2902.           if (strcmp(find.cFileName,".")) {
  2903.             if (find.dwFileAttributes  & FILE_ATTRIBUTE_DIRECTORY ) {
  2904.               if (!RemoveEmptyDir(path+find.cFileName)) {
  2905.                 FindClose(h);
  2906.                 return 0;
  2907.               }
  2908.             } else {
  2909.               if ((!find.nFileSizeLow) && (!find.nFileSizeHigh))
  2910.                 if (!DeleteFile(path+find.cFileName)) {
  2911.                   FindClose(h);
  2912.                   return 0;
  2913.                 }
  2914.             }
  2915.           }
  2916.         }
  2917.       }
  2918.     } while(FindNextFile(h,&find));
  2919.     FindClose(h);
  2920.     
  2921.     SetCurrentDirectory("C:\\");
  2922.     return RemoveDirectory(path.Left(path.GetLength()-1));
  2923.   } else
  2924.     return 0;
  2925.   return TRUE;
  2926. }
  2927.